Hello, I'm a beginner in PHP, HTML, and Apache. When I run the file, the XAMPP has a notice:
Fatal error: Uncaught mysqli_sql_exception: Column 'firstname' cannot be null in C:\xampp\htdocs\connect\connection.php:17 Stack trace: #0 C:\xampp\htdocs\connect\connection.php(17): mysqli_stmt->execute() #1 {main} thrown in
C:\xampp\htdocs\connect\connection.php on line
17
I have two files, one in HTML and one in PHP.
What I have tried:
I double-checked the database on XAMPP but I don't know what's wrong with it.
HTML code:
<!DOCTYPE html>
<!--
Click nbfs:
Click nbfs:
-->
<!DOCTYPE html>
<html>
<head>
<title>Sign-In Form</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
max-width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f2f2f2;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="email"],
input[type="tel"],
select {
width: 100%;
padding: 8px;
border-radius: 3px;
border: 1px solid #ccc;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="container">
<h2>Sign-In Form</h2>
<form action="connect.php" method="post" >
<div class="form-group">
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" required>
</div>
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="text" id="password" name="password" required>
</div>
<div class="form-group">
<label for="contact">Contact Number:</label>
<input type="number" id="contact" name="contact" required>
</div>
<div class="form-group">
<label for="address">Address:</label>
<input type="text" id="address" name="address" required>
</div>
<div class="form-group">
<label for="country">Country:</label>
<input type="text" id="country" name="country" required>
</div>
</form>
<input type="submit" onClick="myFunction()"/>
<script>
function myFunction() {
window.location.href="https://shopee.ph/?gclid=CjwKCAjwyqWkBhBMEiwAp2yUFhWMuFTyZ0Ev3ju0oygGkwXmdptKzZimCT5xr1Wq-lTekgL3xLtbIRoCzH0QAvD_BwE";
}
</script>
</div>
</body>
</html>
PHP code:
<?php
$lastname = filter_input(INPUT_POST, 'lastname');
$firstname = filter_input(INPUT_POST, 'firstname');
$email = filter_input(INPUT_POST, 'email');
$password = filter_input(INPUT_POST, 'password');
$contact = filter_input(INPUT_POST, 'contact');
$address = filter_input(INPUT_POST, 'address');
$country = filter_input(INPUT_POST, 'country');
$conn = new mysqli('localhost', 'root', '', 'entries');
if($conn->connect_error){
die('Connection Failed : ' . $conn->connect_error);
} else{
$stmt = $conn->prepare("insert into entries_(lastname, firstname, email, password, contact, address, country)
values(?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssiss", $lastname, $firstname, $email, $password, $contact, $address, $country, );
$stmt->execute();
echo "sign up successful";
$stmt->close();
$conn->close();
}
?>