簡體   English   中英

PHP SQL Update錯誤

[英]PHP SQL Update error

我在嘗試更新mysql服務器中的表時遇到了一個奇怪的問題。

編碼:

    $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>";
}

在更新組的mysql_query中,我一直收到錯誤,說我在插入desc = blahblahbla時在我的SQL語法中有錯誤。

當我從查詢中取出“desc”部分,並且只插入名稱和類型時,查詢工作正常,但是當我將desc添加回查詢時,它會再次拋出錯誤。 在desc部分中沒有' - 它可以填充它,即使有,我已經在代碼的開頭過濾它們。

任何幫助將不勝感激。

我正在使用CMS,以防你想知道

提前致謝! :)

desc是MySQL中的保留字,用於order by子句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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM