I am working on a school portal project and want to connect my signup form to MySQL database using PHP but its not storing data while submitting it. Constantly getting Undefined index error.
Following is my HTML form code:
<form action="signup.php" method="POST">
<div class="form-row">
<div class="col-lg-7">
<input type="email" class="form-control my-3 p-4" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" placeholder="Email-Address" style="border: 1px solid;" name="email"/>
</div>
</div>
<div class="form-row">
<div class="col-lg-7">
<input type="password" class="form-control my-3 p-4" style="border: 1px solid;" required placeholder="Password" pattern="{8,}" name="password"/>
</div>
</div>
<div class="form-row">
<div class="col-lg-7">
<input type="text" class="form-control my-3 p-4" style="border: 1px solid;" required placeholder="Username" name="username"/>
</div>
</div>
<div class="form-row">
<div class="col-lg-7">
<button type="button" class="btn1 mt-3 mb-3">Register</button>
</div>
</div>
<p>Already have an account? <a href="login.html"> Login</a></p>
</form>
</div>
Following is my PHP code:
<?php
$email_addr=$_POST ['email']; //error for this line
$password=$_POST['password']; //error for this line
$username=$_POST ['username']; //error for this line
$connection= new mysqli('localhost','root','','BHS');
if ($connection->connect_error){
die('COnnection Failed: '.$connection->connect_error);
}else{
$stmt= $connection->prepare("Insert into signup (no,email,password,username) values (?,?,?,?)");
$stmt->bind_param("isss",$no,$email,$password,$username);
$stmt->execute;
echo "Registered successfully";
$stmt->close();
$connection->close();
}
?>