I am creating a register page for a website.
here is my sql code :
| Field | Type | Null | Key | Default | Extra |
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
| course | varchar(50) | NO | | NULL | |
| year | int(1) | NO | | NULL | |
| password | varchar(500) | NO | | NULL | |
| contact | int(20) | NO | | NULL | |
| email | varchar(200) | NO | | NULL | |
php
file is :
<div class="container" style="padding:20px">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading"><h2>Registration Form</h2>
</div>
<div class="panel-body">
<div class="col-lg-6">
<form>
<div class="form-group">
<label>Name :</label>
<input class="form-control" type="string"
id="inputname" name="name" placeholder="Your Name" required>
</div>
<div class="form-group">
<label for="sel1">Select Course :</label>
<select class="form-control" id="course" name="course" required>
<option>B.A. Programme </option>
<option>B.Com </option>
<option>B.Com(Hons.)</option>
<option>B.A.(Hons) Economics</option>
<option>B.A. (Hons.) English</option>
<option>B.A. (Hons.) History</option>
<option>B.A. (Hons.) Hindi</option>
<option>B.A. (Hons.) Political Science</option>
<option>B.A. (Hons.) Sanskrit</option>
<option>B.Sc. (Hons.) Mathematics</option>
<option>B.Sc.(Hons) Statistics</option>
<option>B.Sc.(Hons) Computer Science</option>
<option>B.Sc. Mathematical Science</option>
</select>
</div>
<div class="form-group">
<label for="sel1">Year :</label>
<select class="form-control" id="year" name="year" required>
<option>1 </option>
<option>2</option>
<option>3</option>
</select>
</div>
<div class="form-group">
<label>Password : </label>
<input class="form-control" type="password"
id="password" name="password" placeholder="Password" autocomplete="off" required>
</div>
<div class="form-group">
<label>Confirm Password : </label>
<input class="form-control" type="text"
id="confirm_password" name="confirm_password" placeholder="Confirm password" required>
</div>
<div class="form-group">
<label>Contact No. : </label>
<input class="form-control" type="phonenum"
id="inputnumber" name="contact" placeholder="Your Contact Number" required>
</div>
<div class="form-group">
<label>Email : </label>
<input class="form-control" type="email"
id="inputname" name="email" placeholder="Your Email Id" required>
</div>
<input type="submit" name="submit" value="Register" class="btn btn-default" required>
</form>
</div>
<div class="col-lg-6" style="margin-top:10px">
<div class="panel panel-warning" >
<div class="panel-heading"><h3>Information</h3></div>
<div class="panel-body">
<ul>
<li>Complete the from to register with us.</li>
<li>Fill out the Details carefully.</li>
<li>Fill in your name as it is in your college ID.</li>
<li>Use your correct Email ID and Conatct No. so that we can contact to you.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var password = document.getElementById("password")
, confirm_password = document.getElementById("confirm_password");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
</script>
<?php
include "assets/backend/db.php";
if(isset($_POST['name'])) {
$name=$_POST['name'];
}
$name = $mysqli->escape_string($_POST['name']);
if(isset($_POST['course'])) {
$course=$_POST['course'];
}
if(isset($_POST['year'])) {
$year=$_POST['year'];
}
if(isset($_POST['password'])) {
$password=$_POST['password'];
}
$password = $mysqli->escape_string(password_hash($_POST['password'], md5));
if(isset($_POST['contact'])) {
$contact=$_POST['contact'];
}
$contact = $mysqli->escape_string($_POST['contact']);
if(isset($_POST['email'])) {
$email=$_POST['email'];
}
$email = $mysqli->escape_string($_POST['email']);
// Check if user with that email already exists
$result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error());
// We know user email exists if the rows returned are more than 0
if ( $result->num_rows > 0 ) {
echo 'User with this email already exists!';
header("location: error.php");
}
else { // Email doesn't already exist in a database, proceed...
$sql="INSERT INTO `user`(`name`, `course`, `year`, `password`, `contact`, `email`) VALUES ('$name','$course','$year','$password','$contact','$email')";
// Add user to the database
if ( $mysqli->query($sql) ){
echo "You are successfully registered";
}
else {
echo "Registration failed";
header("location:join.php");
}
}
?>
Errors that I get:
Notice: Undefined index: name in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 103
Notice: Undefined index: password in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 113
Notice: Use of undefined constant md5 - assumed 'md5' in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 113
Warning: password_hash() expects parameter 2 to be long, string given in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 113
Notice: Undefined index: contact in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 117
Notice: Undefined index: email in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 121
Fatal error: Call to undefined method mysqli::error() in C:\xampp\htdocs\PlacementCell\assets\php\register_form.php on line 123
Help me fix this: :)