即時得到這個錯誤錯誤: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 'to, from, message, read) VALUES ('3','2','testmessage','0')' at line 1.
MySql語法錯誤?
的Ive在這幾個小時,這裏什麼也沒有發現在SO或任何其他網站。預先感謝您的幫助。下面是一個簡單的消息傳遞系統的文件。
<?php
session_start();
$id = $_SESSION['id'];
$msg = $_POST['message'];
$theirs = $_POST['value'];
$read = 0;
$con = mysql_connect("127.0.0.1","root","");
mysql_select_db("test", $con);
if (!$con)
die('Could not connect: ' . mysql_error());
$sql = "INSERT INTO messages (to, from, message, read) VALUES ('$theirs','$id','$msg','$read')";
if (!mysql_query($sql,$con))
die('Error: ' . mysql_error());
mysql_close($con);
您的代碼容易受到SQL注入攻擊! – markus
不要使用已棄用,不安全,效率低下的mysql_ * API,而應將mysqli或PDO與預準備語句一起使用。 – markus
我知道,這只是一個測試。病後逃跑,並建立vallidation和參數。我只是想開始somwhere –