這是問題所在。我想用PHP來存儲有多少人選擇芒果是他們最喜歡fruit.Here是代碼:php mysql更新整數變量
mysql_select_db("assignment2", $con);
//$fruitresult = mysql_query("SELECT * FROM Persons");
if(strcasecmp("mango",$fruit)==0){
$fruitsql = mysql_query("SELECT Mango FROM assignment2.fruit");
$fruitresult= mysql_fetch_assoc($fruitsql);
$fruitresult['Mango']=(int)$fruitresult['Mango'];
$fruitresult['Mango']=$fruitresult['Mango']+1;
mysql_query(UPDATE assignment2.fruit SET Mango=".fruitresult['Mango']" WHERE fid=2);
echo"There are total ";
echo $fruitresult["Mango"];
echo " mango <br>";
//echo " testing work";
}
之前我補充更新查詢,它可以得到芒果的數量,並計算它,但是當我添加更新查詢時,出現錯誤:
Parse error: syntax error, unexpected 'assignment2' (T_STRING).
我怎樣才能解決呢?
請,[停止使用'mysql_ *'功能(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-功能合PHP)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。瞭解[準備的陳述](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://jayblanchard.net/demystifying_php_pdo.html)。 –
在更新查詢中添加到Jay Blanchard時,在開始和結束時會丟失逗號。 –
倒逗號?這是一個有興趣的報價單。 – Jessica