I want to submit data from an HTML form into a database table. I am using the code below, but I always get an Error and it doesn't get submitted.
HTML:
<form class="contact_form" action="reminder.php" method="post">
<div class="row">
<div class="col-12">
<div class="form-group row">
<label for="name" class="col-sm-3 col-form-label">Meno*</label>
<div class="col-sm-9">
<input type="text" name="name" class="form-control" placeholder="Meno" required>
</div>
</div>
<div class="col-12 text-right p-0">
<input name="submit" type="submit" class="btn btn-custom-small" value="Odoslať">
</div>
</div>
</div>
</form>
PHP:
<?php
$connection = mysqli_connect("server", "tmpco_bc_02", "password", "tmpco_bc_02", 3311);
if ($connection === false){
die("Connection failed: " . mysqli_connect_error());
}
$name = mysqli_real_escape_string($connection, $_REQUEST['name']);
$sql = "INSERT INTO reminders (name) VALUES ('$name')";
if (mysqli_query($connection, $sql)) {
# Set a 200 (okay) response code.
http_response_code(200);
echo '<p class="alert alert-success">Ďakujeme za tvoj záujem. Mailom ti pripomenieme keď bude čas objednať tvoj Birthday Capsule.</p>';
} else {
# Set a 500 (internal server error) response code.
http_response_code(500);
echo '<p class="alert alert-warning">Error: tvoju žiadosť sa nepodarilo odoslať. Prosím skús to znova.</p>';
}
mysqli_close($connection);
?>
MYSQL: Table is 'reminders' with id|name|email|celebrity_name|bday
After submitting I always get the http_response_code(500)
I've tried looking for any errors, but couldn't solve it. Any idea what could be the problem and how to fix it please?