I really don't see what am I doing wrong. The code simply won't write in the table
if (isset($_POST['submit']))
{
// get the form data
$name = htmlentities($_POST['name'], ENT_QUOTES);
$last = htmlentities($_POST['last'], ENT_QUOTES);
$date = htmlentities($_POST['date'], ENT_QUOTES);
$ran = htmlentities($_POST['ran'], ENT_QUOTES);
if ($name == '' || $last == '' || $date == '' || $ran == '')
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($name, $last, $date, $ran, $error);
}
else
{
// insert the new record into the database
if ($stmt = $mysqli->prepare("INSERT users (name, last, date, ran) VALUES (?, ?, ?, ?)"))
{
$stmt->bind_param("ssss", $name, $last, $date, $ran);
$stmt->execute();
$stmt->close();
}
// show an error if the query has an error
else
{
echo "ERROR: Could not prepare SQL statement.";
}
// redirec the user
header("Location: view.php");
}
}
// if the form hasn't been submitted yet, show the form
else
{
renderForm();
}
// close the mysqli connection
$mysqli->close();
?>
I have the table ready and if I insert in the table manually it works (I have a View.php) but when I run the form nothing, no error, nothing!
Fixed it:
$stmt = $mysqli->prepare("INSERT INTO users (`name`,`last`,`date`,`ran`) VALUES (?, ?, ?, ?)");