sorry if this is very basic, but I've been going around in circles for a while. I'm new to PHP, but none of the documentation seems to help, and none of the previous questions on here quite explain it.
I'm trying to create a simple form that takes user input and creates a record in a database, but the code I have does not seem to recognise the variables provided. When I use strings instead, the insert operation completes, so I know it's not a problem with the connection.
I don't get any error messages - the page refreshes as though nothing had happened.
<form action="" method="post">
<input type="text" name="new_word" id="word" required="required"/>
<input type="text" name="book_ref" id="book" required="required"/>
<input type="text" name="page_range" id="page" required="required"/>
<input type="submit" value="Submit" name="submit"/>
</form>
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("INSERT INTO `words` (`Word`, `Book ID`, `Page`)
VALUES (?,?,?)");
$stmt->bind_param(1, $word);
$stmt->bind_param(2, $book);
$stmt->bind_param(3, $page);
$word = $_POST["new_word"];
$book = $_POST["book_ref"];
$page = $_POST["page_range"];
$stmt->execute();
$conn->close();
}
?>