0
我試圖更新MySQL數據庫具有以下功能,創建減去$席位變量從現有值的值在地方領域的更新語句的值在數據庫中。 下面的代碼返回0,而不是通過$ seats變量的值減少位置值。更新MySQL數據庫的PHP語句
$update_seats = update_places($id);
function update_places($id) {
global $modx;
$table = "`database_name`.`table_name`";
$update_seats = '`places`' - $seats;
$result = $modx->db->update('`places` = ' . $update_seats, $table, '`id` = "' . $id . '" AND `places` > 0');
return $result; // Returns 'true' on success, 'false' on failure.
}
與糾正我的語法任何幫助是極大的讚賞。
我認爲你必須改變'$ update_seats ='\'places \'' - $ seats;'by:'$ update_seats ='\'places \' - '。 $ seats;' – Seb33300
什麼是您的$ modx變量?它也看起來像你還沒有定義$座位。 –
嗨Seb33300 - 感謝您的幫助。 我嘗試了以下錯誤結果消息的建議: 'SQL> UPDATE'database_name'.'table_name' SET'places' ='places' - ($ seats value should be here)WHERE'id' =「1104」 AND'places'> 0' $ seats變量的值未被髮送。 它在功能之外的頁面被進一步聲明。 – Twobears