<?php
$dsn = '';
$user = '';
$password = '';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
<?php
require 'mysqli_connect.php';
if(isset($_POST['submit']) && !empty($_POST['submit'])){
$sth = $dbh->prepare('INSERT INTO test_table(comment) VALUES(?);');
$comment = $_POST['comment'];
$sth->execute(Array($comment));
}
?>
下面的代码将刷新页面,但不会发布到我的数据库(REQUEST_URI
也不会)。如果我把实际的PHP表单名称替换为<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>
它可以正常工作。我试过双引号,单引号,以及介于两者之间的所有内容。这有什么不起作用?
<form action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method = "post">
<p>Comment</p>
<textarea name= "comment" rows="6" cols="50"></textarea><br />
<input type="submit" name= "submit" value="submit" id = "submit">
</form>