SQL结果未在表单提交时更新

时间:2014-05-07 08:50:28

标签: php html mysql forms pdo

我正在将基于mysql的评论系统更新为PDO,但是我遇到了一个奇怪的问题。它完全正常,除了我必须重新加载页面以显示新评论。这之前没有发生过。以下是提交部分的PHP:

if(isset($_POST['submitted'])) {
  $name = stripslashes(htmlspecialchars($_POST['name']));
  $cmt = stripslashes(htmlspecialchars($_POST['comment']));
  $ip = $_SERVER['REMOTE_ADDR'];
  $time = time();
  $cmtpostquery = $pdo->prepare("INSERT INTO commentsdev (post_id,ip,name,content,date) VALUES (:view, :ip, :name, :cmt, :time)");
  $cmtexec = array(":view" => $view, ":ip" => $ip, ":name" => $name, ":cmt" => $cmt, ":time" => $time);

  if((empty($name)) || (empty($cmt))) {
    echo '<div style="color: red; text-align: center; font-weight: bold;">'.MISSING_FIELD.'</div>';
  } 
  else {

    if(!$resp->is_valid) {
      echo '<div style="color: red; text-align: center; font-weight: bold;">'.CAPTCHA_WRONG.'</div>';
    } 
    else {
      $cmtpostquery->execute($cmtexec);
      if($cmtpostquery->errorCode() == 0)
        echo '<div style="color: green; text-align: center; font-weight: bold;">'.CMT_SUCCESS.'</div>';
      else
        echo '<div style="color: red; text-align: center; font-weight: bold;">'.SQL_ERROR.'</div>';
    }
  } 
} 

以下是表单的HTML:

<form method="post">
  <table>
    <tr>
      <td><label for="name">Username:</label></td>
      <td><input name="name" id="name" maxlength="64"/></td>
    </tr>
    <tr>
      <td><label for="comment">Comment:</label></td>
      <td><textarea name="comment" id="comment" style="width: 500px; height: 120px;" maxlength="1500"></textarea></td>
    </tr>
    <tr>
      <td><label for="captcha">Verification:</label></td>
      <td>'.recaptcha_get_html($publickey).'</td>
    </tr>
    <tr>
      <td></td>
      <td><input type="submit" value="Post Comment" name="submitted"/></td>
    </tr>
  </table>
</form>

期待您的指导..

0 个答案:

没有答案