Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP SQL更新错误_Php_Sql_Database - Fatal编程技术网

PHP SQL更新错误

PHP SQL更新错误,php,sql,database,Php,Sql,Database,我在尝试更新mysql服务器中的表时遇到了wierd问题 守则: $name = trim(FilterText($_POST['name'])); $description = trim(FilterText($_POST['description'])); $type = $_POST['type']; if($groupdata['type'] == "3" && $_POST['type'] != "3"){ echo "You may not change t

我在尝试更新mysql服务器中的表时遇到了wierd问题

守则:

    $name = trim(FilterText($_POST['name']));
$description = trim(FilterText($_POST['description']));
$type = $_POST['type'];

if($groupdata['type'] == "3" && $_POST['type'] != "3"){ echo "You may not change the group type if it is set to 3."; exit; } // you can't change the group type once you set it to 4, fool
if($type < 0 || $type > 3){ echo "Invalid group type."; exit; } // this naughty user doesn't even deserve an settings update

if(strlen(HoloText($name)) > 25){
    echo "Name too long\n\n<p>\n<a href=\"".WWW."/groups/".$groupid."/id\" class=\"new-button\"><b>Done</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
} elseif(strlen(HoloText($description)) > 200){
    echo "Description too long\n\n<p>\n<a href=\"".WWW."/groups/".$groupid."/id\" class=\"new-button\"><b>Done</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
} elseif(strlen(HoloText($name)) < 1){
    echo "Please give a name\n\n<p>\n<a href=\"".WWW."/groups/".$groupid."/id\" class=\"new-button\"><b>Done</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";  
} else {
    mysql_query("UPDATE groups SET name = '".$name."', type = $type, desc='".$description."' WHERE id = $groupid AND ownerid = '".USER_ID."' LIMIT 1") or die(mysql_error());
    echo "Editing group settings successful\n\n<p>\n<a href=\"".WWW."/groups/".$groupid."/id\" class=\"new-button\"><b>Done</b><i></i></a>\n</p>\n\n<div class=\"clear\"></div>";
}
$name=trim(FilterText($\u POST['name']);
$description=trim(FilterText($_POST['description']);
$type=$_POST['type'];
如果($groupdata['type']==“3”&&&$\u POST['type']!=“3”){echo“如果将组类型设置为3,则不能更改组类型。”退出;}//一旦将组类型设置为4,则无法更改组类型,傻瓜
如果($type<0 | |$type>3){echo“无效的组类型”。.exit;}//这个淘气的用户甚至不值得更新设置
如果(strlen(全息文本($name))>25){
echo“名称太长\n\n\n\n

\n\n”; }elseif(strlen(全文($description))>200){ echo“说明太长\n\n\n\n

\n\n”; }elseif(strlen(全文($name))<1){ echo“请提供一个名称\n\n\n\n

\n\n”; }否则{ mysql_查询(“更新组集名称=”“$name.”,类型=$type,desc=”“$description.”,其中id=$groupid,ownerid=”.USER_id.“'LIMIT 1”)或死(mysql_error()); echo“编辑组设置成功\n\n\n\n

\n\n”; }
在更新组的mysql_查询中,我不断收到一个错误,指出在插入desc=blahblahbla时,我的SQL语法中有一个错误

当我从查询中取出“desc”部分,只插入名称和类型时,查询工作得很好,但当我将desc添加回查询中时,它再次抛出错误。desc部分中没有“”,这可能会把它塞满,即使有,我也在代码的开头过滤了它们

任何帮助都将不胜感激

我用的是CMS,以防你想知道


提前感谢!:)

desc
是MySQL中的保留字,用于
order by
子句。您必须使用反勾号来逃避:

UPDATE .... `desc`=etc...
            ^--  ^--
当然,你也会被几十个爱管闲事的人所吸引,他们声称使用mysql_*()函数会导致宇宙在5分钟内爆炸。。。4.3…

试试这个

mysql_query("UPDATE `groups` SET `name` = '".$name."', `type` = $type, `desc` = '".$description."' WHERE `id` = '$groupid' AND `ownerid` = '".USER_ID."' LIMIT 1") or die(mysql_error());

谢谢你!我没有点击“订单按'描述'”位。万分感谢!那些爱管闲事的人正在执行一项公共服务。如果你只想将一个长字符串更改2个字符,你通常应该指出更改的位置。我们是人,我们不容易区分。