2012-09-16 7 views
0

mysql 서버의 테이블을 업데이트하려고 할 때 문제가 발생했습니다.PHP SQL 업데이트 오류

코드 다음는 mysql_query에서

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

업데이트하는 그룹, 내가 DESC = blahblahbla를 삽입 할 때 나는이 부분에서 내 SQL 구문에 오류가 있습니다 않다는 오류가 계속 나타납니다.

"desc"부분을 쿼리에서 제거하고 이름과 형식 만 삽입하면 쿼리가 완벽하게 작동하지만 desc를 쿼리에 다시 추가하면 오류가 다시 throw됩니다. 디테일 부분에는 ''이 없기 때문에 코드의 시작 부분에 필터를 걸었습니다.

도움을 주시면 감사하겠습니다. 경우에 당신은 사전에

감사를 궁금해

나는 CMS를 사용하고 있습니다! :)

답변

2

descorder by 절에서 사용하기 위해 MySQL의 예약어입니다.

UPDATE .... `desc`=etc... 
      ^-- ^-- 

그리고 물론

, 당신은 또한 수십 busybodies에 의해 뛰어거야 MySQL의를 사용하여 _ *() 함수가 우주를 일으킬 것이라고 주장 것이다 : 당신은 역 따옴표로 탈출해야합니다

+0

감사를 시도 ... 3 ... 4 ... 5 내파! 나는 "desc by order"를 클릭하지 않았다. 대단히 감사합니다! – zuc0001

+0

바쁜 이들이 공공 서비스를 수행하고 있습니다. – pilcrow

0

가이

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

긴 문자열을 2 문자 만 변경하려는 경우 일반적으로 변경 사항이있는 곳을 지적해야합니다. 우리는 인간이고, 우리는 'diff'를 쉽게하지 않습니다. –