向数据库提交数据时出现错误消息

时间:2020-07-08 10:44:53

标签: php mysql database prepared-statement

在单击“提交”按钮以将数据发送到MySQL数据库时获得此错误消息:

致命错误:未捕获错误:在C:\ xampp \ htdocs \ weinspire \ blog \ index.php:38中对bool的成员函数bind_param()进行调用:堆栈跟踪:#0 {main}抛出在C:\ xampp中\ htdocs \ weinspire \ blog \ index.php,第38行

这是我正在使用的代码:

$table = 'suggestions';
$id = $_SESSION['id'];
$optionOne = '';
$optionTwo = '';

$suggestions = selectAll($table);

if (isset($_POST['new-suggestion'])) {
  global $conn;
  $optionOne = $_POST['optionOne'];
  $optionTwo = $_POST['optionTwo'];
  $sql = "INSERT INTO $table (option_1, option_2) VALUES (:optionOne, :optionTwo)";

  if (!empty($optionOne) && !empty($optionTwo)) {
    $stmt = $conn->prepare($sql);
    $stmt->bind_param('optionOne', $optionOne);
    $stmt->bind_param('optionTwo', $optionTwo);
    $stmt->execute();

  } else {
    echo "All options must be entered";
  }

}

      <form class="suggestion-form" action="index.php" method="POST">
        <h2>Let us suggest your next travel destination...</h2><br>
        <p>Choose from the options and we'll give you ideas for your next trip!</p>
        <p>I love
          <select id="select-one" class="suggestion-dropbox" name="optionOne" onchange="change(event)">
            <option id="views" value="views">stunning views</option>
            <option id="beaches" value="beaches">glorious white beaches</option>
          </select>
        </p>
        <p>I haven't ever been to
          <select class="suggestion-dropbox" name="optionTwo" onchange="placeChange(event)">
            <option value="europe">Europe</option>
            <option value="australia">Australia</option>
          </select>
        before...</p>
          <p>Submit to see our suggestions!</p>
          <button type="submit" name="new-suggestion">Submit</button>

不太清楚我哪里出错了。谢谢

0 个答案:

没有答案