提交我的 html 表单后,我需要添加一条成功消息。我尝试了一些我在网上找到的示例,甚至尝试编写自己的示例,但它们要么不起作用,要么阻止表单提交。我对 PHP 还是很陌生,所以感谢任何帮助。我对消息的显示方式不太挑剔,只要它在那里。我怎样才能做到这一点?谢谢。
<?php
try {
$dbh = new pdo('sqlsrv:Server=xxxx,1433;database=xxxx', 'xxxx', 'xxxx');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$tsql = "INSERT INTO testtable (date, position, referral) VALUES (?, ?, ?)";
$stmt = $dbh->prepare($tsql);
$stmt->execute(array(
$_REQUEST['date'],
$_REQUEST['position'],
$_REQUEST['referral']
));
/* The following call to closeCursor() may be required by some drivers */
$stmt->closeCursor();
// and now we're done; close it
$dbh = null;
}
catch (PDOException $e) {
die("PDO Exception: " . $e->getMessage());
}
catch (Exception $e) {
die("Exception: " . $e->getMessage());
}
?>