My database and PHP code is alright but the problem is that php variable cannot link the input names.
ERROR
Notice: Undefined index: username in C:\xampp\htdocs\site\form.php on line 20
Notice: Undefined index: email in C:\xampp\htdocs\site\form.php on line 21
Notice: Undefined index: password in C:\xampp\htdocs\site\form.php on line 22
Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'firstname' cannot be null
form.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email)
VALUES (:firstname, :lastname, :email)");
$stmt->bindParam(':firstname', $firstname);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':email', $email);
// insert a row
$firstname = $_POST['username'];
$lastname = $_POST['email'];
$email = $_POST['password'];
$stmt->execute();
echo "New records created successfully";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
<!DOCTYPE html>
<html>
<title>Sign Up | Log In</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" type="text/css" href="css/form.css">
<body bgcolor="#00dbff">
<div style="padding-left: 45%;margin-top: 2%;"><button class="button">Sign Up</button></div>
<div style="padding-top: 15%; width: 1000px; padding-left: 30%;">
<form method="POST" action="" autocomplete="off">
<div class="w3-container w3-card-4 w3-light-grey">
<h2>Username:</h2>
<p>
<label>Enter Your Username</label>
<input class="w3-input w3-border w3-round" id="username" name="username" type="text" placeholder="Username....." required pattern="^[A-Za-z0-9]+"></p>
</div>
<div class="w3-container w3-card-4 w3-light-grey">
<h2>Email:</h2>
<p>
<label>Enter Your Email</label>
<input class="w3-input w3-border w3-round" id="email" name="email" type="text" placeholder="Email....." required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"></p>
</div>
<div class="w3-container w3-card-4 w3-light-grey">
<h2>Password:</h2>
<p>
<label>Create a Password</label>
<input class="w3-input w3-border w3-round" id="password" name="password" type="password" placeholder="Password....." required></p>
</div>
<input class="button1" type="submit" name="submit" style="margin-top: 50px; margin-left: 500px;" value="Next>>">
</form>
</div>
</body>
</html>
please help i have no idea what's the error so its my humble request please don't duplicate it or don't close it i have seen so many examples but i am not getting and i tried all but still i can't find the solution. Thank you all