PHP MySQL更新列错误

时间:2013-10-08 19:59:28

标签: php mysql sql-update

我试图用PHP中的MySQL连续更新一些列,如下所示:

$updateuser_sql = "
UPDATE `users`
SET
`HeaderPictureID` = $insertid,
`Bio` = '" . myre($_POST['Bio']) . "',
`ContactEmail` = '". myre($_POST['ContactEmail']) ."',
`PhoneNo` = '". myre($_POST['PhoneNo']) ."',
`TwitterHandle` = '". myre($_POST['TwitterHandle']) ."'
WHERE
`UserID` = '{$_SESSION['userID']}'
";

$mysqli->query($updateuser_sql);

if($mysqli->errno) {
    $handlerreturn['status'] = 'USER_UPDATE_FAILURE';
    console.log('FAILED');
} else {
    $handlerreturn['status'] = 'EXEC_SUCCESS';
    console.log('WORKED');
}

不幸的是,这不起作用,我得到了日志'FAILED'。我怎样才能更准确地找出问题所在并努力解决问题?我做的事情显然是错的吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

将它放在页面的末尾

$_POST["Bio"] = "hi";
$_POST['ContactEmail'] = "cheese";
$_POST['PhoneNo'] = "lion";
$_POST['TwitterHandle'] = "asdl";
$_SESSION['userID'] = "asdf";

$updateuser_sql = "
                    UPDATE `users`
                    SET
                    `HeaderPictureID` = 1,
                    `Bio` = '" . $_POST['Bio'] . "',
                    `ContactEmail` = '". $_POST['ContactEmail'] ."',
                    `PhoneNo` = '". $_POST['PhoneNo'] ."',
                    `TwitterHandle` = '". $_POST['TwitterHandle'] ."'
                    WHERE
                    `UserID` = '{$_SESSION['userID']}'
                    ";

echo $updateuser_sql;

它会吐出发送到数据库的UPDATE语句。我没有看到上面的任何语法错误。我怀疑这个问题与你的自定义“myre”功能有关。