MySql Php更新不起作用?

时间:2013-03-14 04:46:26

标签: php mysql

我在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;
}

3 个答案:

答案 0 :(得分:2)

首先,不要使用mysql_ *函数而是使用PDO,因为您的脚本完全对SQL injections开放。

character = \'ashokkumar2\' 

应该是

`character` = 'ashokkumar2' 
MySQL中的charactera reserved word,所以你需要用tildas来逃避这个词。另一种避免使用保留字问题的方法是使用由下划线分隔的多个单词命名列,例如character_name

如果您需要更多信息,请在运行查询后打印mysql_error()的输出。

请记住,请勿使用mysql_ *而是使用PDOMySQLi

答案 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

也许这会给我们更清楚的答案。