我遇到了MySQL和PHP的問題。如何從PHP表格執行數據庫插入
當我嘗試從PHP用戶,並添加到數據庫中,我得到的錯誤:
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 ''user', 'password') VALUES(,)' at line 1
這是我的PHP代碼:
$user = $_REQUEST["user"];
$password = $_REQUEST["pass"];
// Make a MySQL Connection
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
// Insert a row of information into the table "example"
mysql_query("INSERT INTO accounts('user', 'password')
VALUES($user, $password)")
or die(mysql_error());
echo "Data Inserted!";
一定要過濾數據時你會在數據庫查詢中使用。請參閱[SQL注入](http://en.wikipedia.org/wiki/SQL_injection) – safarov 2012-03-31 18:30:30
您應該使用'$ _POST'而不是'$ _REQUEST',並且您的代碼易受SQL注入攻擊。最後,你真的**不應該**存儲密碼明文。我無法強調這一點。 – kba 2012-03-31 18:31:38
數據現在沒有被插入,爲什麼? – user1305371 2012-03-31 18:44:16