-4
所以我試圖使用PDO來防止sql注入,但在運行我的代碼後,數據不會輸入到數據庫中。如果有人能夠發現錯誤,我會非常感激。嘗試使用PDO後的PHP mysql我的查詢沒有運行
header("location:employees.php");
$connect = mysql_connect("localhost","root","");
if(!$connect){
die(mysql_error($connect));
}
mysql_select_db("employees",$connect) or die(mysql_error());
$dbConnection = new PDO('mysql:dbname=employees;host=localhost;', 'localhost', '');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$name = $_POST['name'];
$position = $_POST['position'];
$wage = $_POST['wage'];
$preparedStatement = $db->prepare('INSERT INTO employees (name, position, wage) VALUES (:name, :position, :wage)');
$preparedStatement->execute(array(':name' => $name,':position' => $position,':wage' => $wage));
mysql_query($preparedStatement);
我沒有收到任何錯誤或任何內容,但用戶沒有輸入數據庫。
'mysql_ *'已被棄用。您應該使用相應的'mysqli_'操作/ – hexafraction
您需要花一些時間閱讀PDO手冊和[這個優秀的PDO教程](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers)。現在你試圖混合'mysql _ *()'API和PDO,但是這兩者完全不兼容。你的PDO代碼應該包含_no_對'mysql _ *()'函數的引用。 –
請告訴我這不是實際的代碼。 – Achrome