需要一些幫助,不斷收到語法錯誤,不能爲我的生活找到錯誤。代碼和變量正在爲其他查詢和表/ dbs工作。MYSQL PHP /命令行語法
錯誤消息
Database Found! Problem updating record. MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET LastName='dfm', WHERE StudentID='123'' at line 2
代碼
if (!empty($_POST['modify']))
{
$connection = mysqli_connect("xxxxx","xxxx","xxxxx");
// Check connection
if (!$connection)
{
echo "Connection failed: " . mysqli_connect_error();
}
else
{
//select table
$dbName="spr14_aglic006";
mysqli_select_db($connection,$dbName) or die(mysqli_error());
echo "Database Found! <br>";
SYNTAX ERROR BELOW
$query =("UPDATE students
SET FirstName='".$_POST['firstName']."', LastName='".$_POST['lastName']."',
WHERE StudentID='".$_POST['PID']."'");
SYNTAX ERROR ABOVE
$res = mysqli_query($connection,$query);
if ($res)
{
echo "<p>Record Updated<p>";
}
else
{
echo "Problem updating record. MySQL Error: " . mysqli_error($connection);
}
}
mysqli_close($connection);
}
有什麼幫助嗎?
** **危險面前:你是**易受[SQL注入攻擊(http://bobby-tables.com/)**,你需要來自[自衛](http://stackoverflow.fcom/questions/60174/best-way-to-prevent-sql-injection-in-php)。 – Quentin
也許在你的查詢中試着不換行 – Ajouve
它是查詢周圍的括號嗎? ''查詢= _(_「'和'」'「_)_;' – Sam