我試圖阻止使用PHP與PDO的SQL注入。我用它作爲參考。 http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers。我的代碼不會給我任何錯誤,但進入的值都是null。PHP阻止SQL注入
我試圖插入vlaues是不空。我知道這是因爲我他們echo'ed出來: echo "\nDate: ".$date." Name: ".$name." mail: ".$mail."Comment: ".$comment." website: ".$website;
$sql = "INSERT post SET timeDate = :timeDate and name = :name and mail = :mail and comment = :comment and website = :website";
$stmt = $db->prepare($sql);
$stmt->bindParam(":timeDate", $date);
$stmt->bindParam(":name", $name);
$stmt->bindParam(":mail", $mail);
$stmt->bindParam(":comment", $comment);
$stmt->bindParam(":website", $website);
$stmt->execute();
您首先需要學習**基本的SQL語法**。 https://dev.mysql.com/doc/refman/5.7/en/update.html –
在附註中,您實際上並不需要如此漫長而曲折的代碼,實際上兩條線足夠了:[PDO示例: UPDATE query using PDO](https://phpdelusions.net/pdo_examples/update) –
'$ sql =「INSERT post SET name =?,mail =?」;' '$ db-> prepare($ sql) - >執行([$ name,$ mail]);'但是這個注入是否安全? – Fig