在过去的5个小时里,我一直试图弄清楚为什么这个表单在看似正确的时候不会将数据插入MySQL。
表格
<form action="insertComment.php" method="POST">
<input type="hidden" name="article_id" value="<?php echo $article_uid;?>">
<input type="text" name="name" placeholder="Enter your name" required/>
<input type="email" name="email" placeholder="Enter your email" required/>
<textarea type="text" name="comment" placeholder="Join the discussion..." required></textarea>
<input type="submit" class="submit" value="Submit Comment"/>
</form>
然后在comment.php
include '../../../libraries/phpClass/commentClass.php';
$commentClass = new commentClass();
if(isset($_POST['name']) AND isset($_POST['email']) AND isset($_POST['comment']) AND isset($_POST['article_id']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$article_id = $_POST['article_id'];
$data = $commentClass->insertComment($name, $email, $comment, $article_id);
}
这是公共职能..
public function insertComment($name, $email, $comment, $article_id)
{
$sth = $this->db->prepare("INSERT INTO articles_comment(name, email, comment, article_id) VALUES (:name, :email, :comment, :article_id)");
$sth->execute(array(
':name' => $name,
':email' => $email,
':comment' => $comment,
':article_id' => $article_id
));
}
从我所看到的没有任何错误,我无法看到任何为什么它不会插入值..没有任何错误..