Getting this error message when clicking the submit button to send data to MySQL database:
Fatal error: Uncaught Error: Call to a member function bind_param() on bool in C:\xampp\htdocs\weinspire\blog\index.php:38 Stack trace: #0 {main} thrown in C:\xampp\htdocs\weinspire\blog\index.php on line 38
This is the code I'm using:
$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>
Not too sure where I've gone wrong. Thanks