PHP MySQL查询包含关键字/保留字 [英] PHP MySQL query containing keywords/reserved words

查看:262
本文介绍了PHP MySQL查询包含关键字/保留字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新包括HTML数据在内的MySQL数据时遇到了问题,我不断修复错误;但是,一旦纠正了一个错误,就会给另一个错误.当前错误如下:

I have encountered an issue with updated my MySQL data which includes HTML data, I continuously fixed errors; however, once one error is fixed it gives another. The current error is as follows:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='Live updates to certain games will also be posted on this website througho' at line 1

我已经进行了将近3天的Stack Overflow清理工作,没有任何明确的答案.所以我希望有人能找到这个!

I have been scavenging on Stack Overflow for nearly 3 days without any definitive answers. So I am hoping someone can find this!

这是我的PHP表单代码:

Here is my PHP form code:

 if (isset($_POST['submit'])) { 
    $WName = mysql_prep($_POST['wname']);
    $SName = mysql_prep($_POST['sname']);
    $Desc = mysql_prep($_POST['desc']);
    $LogoURL = mysql_prep($_POST['logourl']);
    $aboutPage = mysql_prep($_POST['aboutpage']);
    $query = "UPDATE settings SET name='$WName',subName='$SName',desc='$Desc',logoUrl='$LogoURL',about='$aboutPage'";
    // $query = mysql_prep($query);
    mysql_query($query) or die(mysql_error());
     header("Location: settings.php?=success");
 } 

函数

mysql_prep()

可以在Internet上找到,即在这里: https://gist.github .com/ZachMoreno/1504031

can be found on the internet, namely here: https://gist.github.com/ZachMoreno/1504031

这是HTML表单:

<form role="form" action="" method="post">
    <!-- text input -->
    <div class="form-group">
        <label>Website Name</label>
        <input type="text" name="wname" class="form-control" placeholder="
            <?php echo $row['name']; ?>" value="
            <?php echo $row['name']; ?>" />
        </div>
        <div class="form-group">
            <label>Sub Name</label>
            <input type="text" name="sname" class="form-control" placeholder="
                <?php echo $row['subName']; ?>" value="
                <?php echo $row['subName']; ?>" />
            </div>
            <div class="form-group">
                <label>Description</label>
                <textarea name="desc" class="form-control" rows="3" placeholder="
                    <?php echo $row['desc']; ?>" >
                    <?php echo $row['desc']; ?>
                </textarea>
            </div>
            <div class="form-group">
                <label>Logo URL</label>
                <input type="text" name="logourl" class="form-control" placeholder="
                    <?php echo $row['logoUrl']; ?>" value="
                    <?php echo $row['logoUrl']; ?>"  />
                </div>
                <div class="form-group">
                    <label>About Page</label>
                    <textarea class="form-control" name="aboutpage" rows="6" placeholder="
                        <?php echo $row['about']; ?>">
                        <?php echo $row['about']; ?>
                    </textarea>
                </div>
                <div class="box-footer">
                    <input type="submit" name="submit" class="btn btn-primary" value="Submit" style="margin-left:-10px;" />
                </div>
            </form>

非常感谢您能提供的任何帮助,我希望能解决这个问题,我的目的是用它来帮助遇到相同/相似问题的未来访客.

Thanks very much for any assistance that you can provide, I hope this can be figured out and I aim to use this to assist future visitors who encounter the same/similar issues.

推荐答案

简直不敢相信我之前没有看到这一点.我在MySQL上遇到的问题是数据库的列名称为"desc",我最初的想法是它的意思是描述",但实际上它与关键字"descending"冲突.这产生了语法错误.

Can't believe I didn't see this earlier; the issue I had with MySQL was that the database had the column name 'desc' which I originally had the idea that it meant 'description' but in fact it was conflicting with the keyword 'descending'. This gave the syntax error.

这是我在MySQL文档中找到的内容; 9.3关键字和保留字 :

Here is what I found on the MySQL documentation; 9.3 Keywords and Reserved Words :

关键字是在SQL中具有重要意义的单词.某些关键字(例如SELECT,DELETE或BIGINT)已保留,需要特殊对待才能用作表名和列名之类的标识符.内置函数的名称也可能如此.

Keywords are words that have significance in SQL. Certain keywords, such as SELECT, DELETE, or BIGINT, are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.

在上方的该网络链接上,您可以看到不应该使用的关键字/保留字列表,或者应包含反斜杠(我将不再赘述).

On that web link above you can see a list of keywords/reserved words that shouldn't be used or should include back slashes (which I won't go into).

我的解决方案?不要使用保留字作为标识符!

您可以做的最简单的解决方案就是避免使用这些单词.我通过将标识符更改为描述"来防止使用保留字"desc".

The easiest solution that you can do is to simply avoid using these words. I prevented using the reserved word 'desc' by changing the identifier to 'description'.

感谢您的所有帮助!希望这对以后的人们有所帮助.

Thanks for all your help! Hope this assists people in the future.

这篇关于PHP MySQL查询包含关键字/保留字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆