我试图从 MySQL 数据库中检索值并将其转换为 int,而不是向其添加 3,而不是尝试将更新 int 存储到数据库中。我没有收到任何错误或任何东西。我从数据库中检索的初始值为 5 及以上我试图添加 3 而不是更新数据库。现在更新的值应该是 8,但它不是只是 3。我不知道我做错了什么,所以请帮帮我。
我的 index.php 中的 php 代码如下:
else if ($tag == 'addQuestion'){
$username = mysql_real_escape_string($_POST['username']);
$question = mysql_real_escape_string($_POST['question']);
$tag1 = mysql_real_escape_string($_POST['tag1']);
$tag2 = mysql_real_escape_string($_POST['tag2']);
$tag3 = mysql_real_escape_string($_POST['tag3']);
$time = $_POST['time'];
$addQu = $db->addQuestion($username, $question, $tag1, $tag2, $tag3,$time);
if($addQu){
$q_id = $addQu["id"];
$addQTA = $db->addQTA($username,$q_id,$question,$tag1,$tag2,$tag3);
if($addQTA){
$getKP= $db->getKP($username);
if($getKP){
//Having trouble at this part
$kp = (int)$getKP['karma_points'];
$ask_question_points = $kp + 3;
$updateKP= $db->updateKP($username,$ask_question_points);
if($updateKP){
$response["error"] =1;
$response["msg"] = "updateKP in AddQuestion Succesfull";
echo json_encode($response);
}
else{
$response["error"] =1;
$response["error_msg"] = "Error updateKP in AddQuestion";
echo json_encode($response);
}
}
else{
$response["error"] =1;
$response["error_msg"] = "Error inserting getKP in AddQuestion";
echo json_encode($response);
}
}
else{
$response["error"] =1;
$response["error_msg"] = "Error inserting QTA";
echo json_encode($response);
}
}else{
$response["error"] =1;
$response["error_msg"] = "Error inserting question";
echo json_encode($response);
}
}
下面是 DB_functions.php 中处理更新查询的函数代码:
public function updateKP($username,$karma_points){
$result = mysql_query("UPDATE users SET karma_points = '$karma_points' WHERE username = '$username'") or die(mysql_error());
return($result);
}
谢谢你!!