我有我的代碼來更新我的MySQL數據庫,它正在運行,但是當我使用phpmyadmin檢查rcords時沒有更新數據庫。 plae hlp me。PHP嘗試更新MySQL數據庫不會更新
$database = "carzilla";
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$manufacturerTable = $_POST[vehicleManufacturer];
$numberToSearch = $_POST[vehicleIdNo];
$engineType = $_POST[engineType];
$engineCC = $_POST[engineCC];
$year = $_POST[year];
$numberofDoors = $_POST[numberofDoors];
$tireSize = $_POST[tireSize];
$chasisNumber = $_POST[chasisNumber];
$vehicleMake = $_POST[vehicleMake];
$price=$_POST[price];
mysql_select_db("$database", $con);
$sql = mysql_query("UPDATE $manufacturerTable SET username='vehicleMake',
engineType='$engineType', engineCC='$engineCC', year='$year', chasisNo='$chasisNumber', numberOfDoors='$numberofDoors' ,numberOfDoors='$numberofDoors', tireSize='$tireSize', price='$price' WHERE `index` ='$id'");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo 'record has been successfuly';
mysql_close($con);
?>
老兄,你的PHP很容易受到SQL注入幾乎所有可能的方式。你*真*不應該像你那樣相信你的'$ _POST'。 – Romain
你的查詢有一個'WHERE index ='$ id'',但我在你的代碼中看不到'$ id'。你真的想要更新一個現有的記錄,或者你想創建一個新的? – Romain
需要看sql表結構 – Julien