Mysqli更新命令不更新

时间:2013-02-12 09:36:29

标签: php mysqli

include('config.php');
mysqli_select_db($mysqli, "real");
if ($transaction == "Success" && $currency == "USD") {
    $user_ids = '".$user_id."'; $total_cred = `user_credits` +'".$package_credits."';
    $add = $mysqli->prepare("UPDATE `users` SET `user_credits` = ?  WHERE `user_id` =  ?");
    $add->bind_param('si', $total_cred,$user_ids); $add->execute();
}  

代码不会抛出任何错误,也不会更新数据库。

2 个答案:

答案 0 :(得分:2)

将if块更改为

//    $user_ids = '".$user_id."'; REMOVE THE statement
//    $total_cred = `user_credits` +    '".$package_credits."'; REMOVE THIS too
$add = $mysqli->prepare("UPDATE `users` SET `user_credits` = `user_credits` + ?  WHERE `user_id` =  ?");
$add->bind_param('ii', $package_credits, $user_id ); $add->execute();

让MySQL尽其所能。

答案 1 :(得分:-1)

试试这个:

include('config.php');
mysqli_select_db($mysqli, "real");
if ($transaction == "Success" && $currency == "USD") 
{
    $user_ids = '".$user_id."'; 
    $total_cred = user_credits +'".$package_credits."';
    $add = $mysqli->prepare("UPDATE users SET user_credits = ?  WHERE user_id =  ?");
    $add->bind_param('si', $total_cred,$user_ids); 
    $add->execute();
}