douan7601
2014-05-04 17:31
浏览 41
已采纳

php / pdo INSERT函数不在phpmyadmin中显示字段内容

I'm trying to insert content from my form into my database. I'm using twitter bootstrap 3 to layout my website but here is the form;

<form class="form-horizontal" method="post" action="assets/mailreview.php" role="form">
<fieldset>

<!-- Form Name -->
<legend>Submit you're review</legend>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="firstname">First Name:</label>
  <div class="col-md-4">
  <input id="firstname" name="firstname" placeholder="" class="form-control input-md" type="text">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="surname">Last Name:</label>
  <div class="col-md-4">
  <input id="surname" name="surname" placeholder="" class="form-control input-md" type="text">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="email">Email:</label>
  <div class="col-md-4">
  <input id="email" name="email" placeholder="" class="form-control input-md" type="text">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" for="title">Job Title:</label>
  <div class="col-md-4">
  <input id="title" name="title" placeholder="New kitchen.." class="form-control input-md" type="text">

  </div>
</div>

<!-- Textarea -->
<div class="form-group">
  <label class="col-md-4 control-label" for="brief">Description:</label>
  <div class="col-md-4">
    <textarea class="form-control" id="brief" name="brief">please type you're review here</textarea>
  </div>
</div>

<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label" for="submitbtn">Submit:</label>
  <div class="col-md-4">
    <button id="submitbtn" name="submitbtn" class="btn btn-primary">Submit</button>
  </div>
</div>

</fieldset>
</form>

As you can see I have set the submit action to respond to mailreview.php on doing so I receive no errors(after several and i mean several) however the form properties will not display in myphpadmin. It does insert a new row but not the field content.

here is mailreview.php

    <?php
    include_once("config.php");

$sql = "INSERT INTO review (firstname, lastname, email, title, brief) values(:firstname,:lastname,:email,:title,:brief)";

$stmt = $db->prepare($sql);

$stmt->bindParam(':firstname', $_POST['firstname'], PDO::PARAM_STR);
$stmt->bindParam(':lastname', $_POST['surname'], PDO::PARAM_STR);
$stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
$stmt->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
$stmt->bindParam(':brief', $_POST['brief'], PDO::PARAM_STR);

$stmt->execute();

?>

any advice or support would be very grateful!!!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • duan1933 2014-05-04 17:54
    最佳回答

    You are missing colons on your list of values.

    Change this:

     $sql = "INSERT INTO review (firstname, lastname, email, title, brief) values(firstname,lastname,email,title,brief)";
    

    to:

     $sql = "INSERT INTO review (firstname, lastname, email, title, brief) values(:firstname,:lastname,:email,:title,:brief)";
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题