$check_verified_user = mysqli_query("SELECT * from user_verified where user_mail = '$payer_email'");
$user_verified = mysqli_fetch_array(mysqli_query($conDB, "SELECT * FROM user_verified where user_mail = '$payer_email'"));
if(mysqli_num_rows($check_verified_user) > 0) {
mysqli_query($conDB, "UPDATE user_verified SET total_paid = total_paid + '$payment_amount' where user_mail = '$payer_email'");
} else {
mysqli_query($conDB, "INSERT into user_verified (user_mail,total_paid) VALUES ('$payer_email', '$payment_amount')");
}
我不知道我的脚本出了什么问题,它会检查该行是否存在,然后如果存在,则应更新该行,但会插入另一行,我不明白...
最佳答案
试试看。
$query = "SELECT * FROM user_verified WHERE user_mail = $payer_email";
$check_verified_user = mysqli_query($conDB, $query);
您基本上没有为它提供数据库连接,因此它总是返回不大于0的行。就个人而言,我总是首先将查询放入其自己的变量中,这将确保您不会忘记
mysqli_query()
函数的参数。它还使它更易于阅读,并允许您在需要的其他地方使用查询。