我試圖插入數據庫某種形式發佈數據,但它顯示了錯誤:PHP表單數據插入在MySQL
Error: INSERT INTO user_data (name, age, gender,happy,sad,angry) VALUES (Sourav,23,male,3.5,2.75,1.5)
Unknown column 'Sourav' in 'field list'
我使用的查詢:
$sql = "INSERT INTO user_data (name, age, gender,happy,sad,angry)
VALUES (" . $name . "," . $age . "," . $gender . "," . $happyness . "," . $sadness . "," . $angryness . ")";
永遠不要直接將用戶輸入到數據庫中查詢。至少使用某種參數轉義或mysqli/pdo來避免mysql注入。 – Sven