我在Mysql Php中面临更新问题..
以下是我正在使用的代码
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$char ='this is chara'; //$_REQUEST['character'];
$des = $_REQUEST['des'];
$id = $_REQUEST['id'];
$sql_update = "UPDATE cast SET name ='".$name."',Gendor ='".$email."', character = \'ashokkumar2\',description ='".$des."' WHERE id = '".$id."'";
$result=mysql_query( $sql_update);
if ($result){
echo 1;
}
答案 0 :(得分:2)
首先,不要使用mysql_ *函数而是使用PDO,因为您的脚本完全对SQL injections开放。
character = \'ashokkumar2\'
应该是
`character` = 'ashokkumar2'
MySQL中的character
是a reserved word,所以你需要用tildas来逃避这个词。另一种避免使用保留字问题的方法是使用由下划线分隔的多个单词命名列,例如character_name
。
如果您需要更多信息,请在运行查询后打印mysql_error()的输出。
答案 1 :(得分:0)
试试这个
$sql_update = "UPDATE cast SET name=$name,Gendor=$email,character='$char',description=$des WHERE id = $id";
$result=mysql_query($sql_update);
if ($result){
echo 1;
}
答案 2 :(得分:0)
如果上述答案不起作用,您可以复制并粘贴以下输出: print $ sql_update
也许这会给我们更清楚的答案。