Html code:
<html>
<head>
</head>
<body>
<p><h1>Student Information Input Form</h1></p>
<section>
<form method="POST" action="connection.php">
<p><b>Name:</b> <input type="text" id="name" name="name"></input></p>
<p><b>Username:</b> <input type="text" id="username" name="username"></input></p>
<p><b>Password:</b> <input type="password" id="password" name="password"></input></p>
<p><b>Email:</b> <input type="email" id="email" name="email"></input></p>
<p><input type="submit" id="submit" name="submit"></p>
</form>
</section>
</body>
</html>
PHP Code:
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="newdb";
//Create Connection
$conn=new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//get values from form
if (isset($_POST['name'])) {
$nameForm=$_POST['name'];
}
if (isset($_POST['username'])) {
$usernameForm=$_POST['username'];
}
if (isset($_POST['passsword'])) {
$passwordForm=$_POST['password'];
}
if (isset($_POST['email'])) {
$emailForm=$_POST['email'];
}
//Insert Values
$sql = "INSERT INTO userinfo (name, username, password, email) VALUES ('$nameForm', '$usernameForm', '$passwordForm', '$emailForm')";
//To check whether data is inserted properly or not
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Error Message:
Notice: Undefined variable: passwordForm in C:\xampp\htdocs\Project2_php db\connection.php on line 28 New record created successfully
On clicking The submit button I am getting the above error and in the database, all the values are stored as zero.