Toshi Blake Toshi Blake - 1 year ago 65
HTML Question

Errors while submitting the form ( php & bootstrap)

I'm an intern at the company right now, and I've to create registration and login form for the website.

Currently I'm facing the problem with registration.

this is the errors

I declared everything like in the tutorials but still getting these errors and can't figure out it.

this is the php script:

//connection to database


//Validation for Username
$errors = array();
$errors['user_name'] = 'Please fill in your Username';//Username

$user_name = mysqli_real_escape_string($con, trim($_POST['user_name']));
//validation to check if the username posted is in use.
if($check = $connection->query("SELECT * FROM student WHERE username = '$user_name'")){
$errors['user_name'] = 'Username in use';
$errors['user_name'] = 'the query did not work';


//validation for password
$errors['pword'] = 'Please fill in password';
$pword = $_POST['pword'];
//checking if the password ented in verify password is matching the password field
$errors['pwordConfirm'] = 'Please verify password';
$pwordConfirm = $_POST['pwordConfirm'];

$errors ['pwordConfirm'] = 'passwords do not match';
$password = mysqli_real_escape_string($connection,trim($_POST['pword']));
// $password = sha1($password);

// validation for name textfield
$errors['fname'] = 'Please fill in your name ';
$fname = mysqli_real_escape_string($connection,trim($_POST['customer_name']));

// validation for passport textfield
$errors['passport'] = 'Please fill in your passport ';
$passport = mysqli_real_escape_string($connection,trim($_POST['passport']));

//validation for email
$errors['email'] = 'Please fill in your email';
$email = mysqli_real_escape_string($connection,trim($_POST['email']));

if($check = $connection->query("SELECT * FROM customer WHERE email = '$email'")){
$errors['email'] = 'Email in use';
$errors['email'] = 'the query did not work';

//validation for phone no
$errors['mobinput'] = 'Please fill in your phone';
$mobinput = mysqli_real_escape_string($connection,trim($_POST['mobinput']));

//validation for phone no
$errors['homemobinput'] = 'Please fill in your phone';
$homemobinput = mysqli_real_escape_string($connection,trim($_POST['homemobinput']));

//validation for phone no
$errors['dob'] = 'Please fill in your phone';
$dob = mysqli_real_escape_string($connection,trim($_POST['dob']));

//validation for gender column to be selected.
$errors['sex'] = 'Please fill in your gender';

if( $_POST['sex'] == 'default')
$errors['sex'] = 'Please select your gender';
$gender = mysqli_real_escape_string($connection,trim($_POST['sex']));

//validation for mstatus
$errors['mstatus'] = 'Please fill in your phone';
$mstatus = mysqli_real_escape_string($connection,trim($_POST['mstatus']));

//validation for education
$errors['education'] = 'Please fill in your phone';
$education = mysqli_real_escape_string($connection,trim($_POST['education']));
//validation for occupation
$errors['occupation'] = 'Please fill in your phone';
$occupation = mysqli_real_escape_string($connection,trim($_POST['occupation']));

//validation for address
$errors['address'] = 'Please fill in your address';
$address = mysqli_real_escape_string($connection,trim($_POST['address']));

//validation for wmcauin
$errors['wmcauin'] = 'Please fill in your phone';
$wmcauin = mysqli_real_escape_string($connection,trim($_POST['wmcauin']));
//validation for tp
$errors['tp'] = 'Please fill in your phone';
$tp = mysqli_real_escape_string($connection,trim($_POST['tp']));
//validation for wauinmassage
$errors['wauinmassage'] = 'Please fill in your phone';
$wauinmassage = mysqli_real_escape_string($connection,trim($_POST['wauinmassage']));

//validation for hduhabttbc
$errors['hduhabttbc'] = 'Please fill in your phone';
$hduhabttbc = mysqli_real_escape_string($connection,trim($_POST['hduhabttbc']));

$query = "INSERT INTO student ";
$query .= "(`Student_id`, `Full_Name`, `Adress`, `Ic_Passport_no`, `Date_of_Birth`, `Mobile_No`, `Home_No`,
`Email`, `Marital_status`, `Occupation`, `Education`, `Why_interest_in_Massage`, `How_did_you_know_about_us`,
`Registration_date`, `Traner_Preference`, `course_of_interest`, `gender`, `username`, `password`, `user_type`) ";
$query .= "VALUES ('','$fname','$address','$sex','$passport','$dob','$mobinput','$homemobinput',
'$email', '$mstatus', '$occupation', '$education', '$wauinmassage','$hduhabttbc',
'', '$tp', '$wmcauin','$sex', '$user_name', '$password', 'S' )";

$register = $connection->query($query);

$customer_id = $connection->query("SELECT customer_id FROM customer WHERE email = '$email' and user_name = '$user_name'")->fetch_object()->customer_id;

$query1 = "INSERT INTO cart ";
$query1 .= "(customer_id) ";
$query1 .= "VALUES ('customer_id')";

$addCart = $connection->query($query1);

if(!$register && !addCart){

echo $query;
$message = 'Registration successfully completed, You can now login';


This is the html form:

<!-- PopUp registration Form -->
<div id="signup" class="modal fade" role="dialog">
<div class="modal-dialog">

<!-- PopUp registration Form content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Massage Course Registration Form</h4>

<div class="modal-body">
<form method="post" class="form-signin form-group">

<label for="usernameInput" class="usernameinput">Username</label>
<input type="text" class="form-control" id="user_name" name="user_name">


<label for="passwordinput">Password</label>
<input type="password" class="form-control" id="passwordinput" name="pword">


<label for="NameInput">Name</label>
<input type="text" class="form-control" id="InputName" placeholder="Jane Doe" name="fname">


<label for="ICinput">I.C/Passport No.</label>
<input type="text" class="form-control" id="ICinput" name="passport">


<label for="EmailInput">Email</label>
<input type="email" class="form-control" id="EmailInput" placeholder="" name="email">


<label for="mobinput">Mobile No</label>
<input type="number_format" class="form-control" id="mobinput" name="mobinput">


<label for="homemobinput">Home No</label>
<input type="number_format" class="form-control" id="homemobinput" name="homemobinput">


<label for="DOBinput">Date of Birth</label>
<input type="date" class="form-control" id="DOBinput" name="dob">


<label for="SexInput">sex</label>
<select class="form-control" id="SexInput" name="sex">


<label for="MaritalStatusInput">Marital Status</label>
<select class="form-control" id="MaritalStatusInput" name="mstatus">


<label for="EducationInput">Education</label>
<input type="text" class="form-control" id="EducationInput" name="education">


<label for="OccupationInput">Occupation</label>
<input type="text" class="form-control" id="OccupationInput" name="occupation">


<label for="Addressinput">Address</label>
<input type="text" class="form-control" id="Addressinput" name="address">


<label for="CourseSelection">Which massage course are you interested in?</label>
<select class="form-control selectpicker" id="CourseSelection" name="wmcauin">
<optgroup label="Professional">
<option>Full Body Massage</option>
<option>Reflexology Course</option>
<option>Aromatherapy Course</option>
<optgroup label="Advanced">
<option>Pre and Post Natal</option>
<option>Slimming Massage</option>
<option>Lymphatic Drainage</option>
<option>Spa and Facial</option>
<option> Raindrop Techniques</option>
<option>Male Health</option>
<option>Sport Injury</option>
<option>Traditional Malay</option>


<label for="TrainerPreferenceInput">Trainer Preference</label>
<select class="form-control" id="TrainerPreferenceInput" name="tp">
<option>Male Trainer</option>
<option>Female Trainer</option>


<label for="InterestFeedbackInput">Why are you interedted in Massage?</label>
<input type="text" class="form-control" id="InterestFeedback" name="wauinmassage">


<label for="ReferalFeedbackInput">How did you heard about Tim BodyCare Training Centre</label>
<input type="text" class="form-control" id="ReferalFeedbackInput" name="hduhabttbc">
<div class="form-group">
<button type="submit" class="btn btn-primary" name="btn-signup">
<i class="glyphicon glyphicon-open-file"></i>&nbsp;SIGN UP

<div class="modal-footer">
<p>By clicking submit, you agreeing with our terms and conditions</p>

<!-- End of PopUp registration Form -->

Note that php script and html form all in one file.

Answer Source

Change the variable name in training_index.php

$conn and $connection to $conn

Because in connection.php file you mentioned your db connection variable name as

 $con = new mysqli($servername, $username, $password, $dbname);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download