<?php
$con=mysqli_connect("localhost","xx","xx","xx");
$con2=mysqli_connect("localhost","xx","xx","xx");
$name = $_POST["name"];
$state = $_POST["state"];
$feedback = $_POST["feedback"];
//$ad_id= $_POST["ad_id"];
$rate= $_POST["rate"];
$ad_rating = $_POST["ad_rating"];
$ad_id= $_POST["ad_id"];
$statement = mysqli_prepare($con, "INSERT INTO user_feedback(name, state, feedback, ad_id, rate) VALUES (?,?,?,?,?)");
$statement2 = mysqli_prepare($con, "UPDATE post_ads SET ad_rating= $ad_rating + $ad_rating WHERE ad_id= ?");
mysqli_stmt_bind_param($statement, "sssss", $name, $state, $feedback, $ad_id, $rate);
mysqli_stmt_bind_param($statement2, "ss", $ad_rating, $ad_id);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_stmt_execute($statement2);
mysqli_stmt_close($statement2);
mysqli_close($con);
?>
我目前在做一個移動應用程序,並需要將數據分析到數據庫,這是我的PHP代碼。
我目前有我的數據庫表中的ad_rating屬性,我有附加圖像鏈接在這裏。
我的問題是,每當我更新ad_rating的新值時,我應該如何將它添加到前一個?示例ad_rating = 4,所以當我嘗試通過發送ad_rating = 3做一個新的請求時,我想添加它與我以前的ad_rating值是4,所以ad_rating內的值變爲7.
你的第二個查詢有1個佔位符,但2個綁定。錯誤http://php.net/manual/en/mysqli.error.php –
你有2個連接的原因嗎? –
我需要解析數據到兩個不同的表。 –