我一直在尝试制定准备好的语句,并在其中使用 $_POST 变量,但我在网上看到的任何东西似乎都不起作用。我知道这些问题是为了展示适当的研究,但我在网上找不到任何与这个问题相匹配的东西。请告诉我我做错了什么。
$dbh = new PDO('mysql:host=localhost;dbname=dbname', 'user', 'pass');
$currentdate = date("Y-m-d");
$key = md5(microtime().rand());
try {
$query = $dbh->prepare("INSERT INTO requests (formname, formemail, formphone, formpostcode, formitem, formnotes, formbudget, formdatefor, currentdate, deletekey, resolved, deleted)
VALUES (:name, :email, :phone, :postcode, :item, :notes, :budget, :datefor, :curentdate, :key, '0', '0')");
$params = array_intersect_key($_POST, array('name', 'email', 'phone', 'postcode', 'item', 'notes', 'budget', 'datefor', 'currentdate', 'key'));
$query->execute($params);
}
catch (PDOException $e) {
error_log($e->getMessage());
die("An error occurred, contact the site administrator.");
}