我試圖在PHP中創建一個更新函數,但是記錄似乎並沒有隨着更新而改變。我創建了一個JSON對象來存放傳遞給這個文件的值,並且根據我運行的Firebug Lite控制檯,這些值被輸出得很好,所以它在sql方面可能有些問題。任何人都可以發現問題嗎?我會很感激幫助!在PHP中不更新的SQL表格
<?php
$var1 = $_REQUEST['action']; // We dont need action for this tutorial, but in a complex code you need a way to determine ajax action nature
$jsonObject = json_decode($_REQUEST['outputJSON']); // Decode JSON object into readable PHP object
$name = $jsonObject->{'name'}; // Get name from object
$desc = $jsonObject->{'desc'}; // Get desc from object
$did = $jsonObject->{'did'};// Get id object
mysql_connect("localhost","root",""); // Conect to mysql, first parameter is location, second is mysql username and a third one is a mysql password
@mysql_select_db("findadeal") or die("Unable to select database"); // Connect to database called test
$query = "UPDATE deal SET dname = {'$name'}, desc={'$desc'} WHERE dealid = {'$did'}";
$add = mysql_query($query);
$num = mysql_num_rows($add);
if($num != 0) {
echo "true";
} else {
echo "false";
}
?>
請注意'{'$ name'}'和''{$ name}''之間有區別。也許你的WHERE條件不正確。 – EmCo 2013-02-19 18:11:29