提交表单时出错(php& bootstrap)

时间:2016-08-08 08:43:13

标签: php html forms bootstrap-modal

我现在是该公司的实习生,我将为该网站创建注册和登录表单。

目前我正面临注册问题。

this is the errors

我在教程中声明了所有内容,但仍然遇到这些错误而无法弄清楚。

这是php脚本:

<?php
//connection to database
include('connection.php');

if ($_SERVER['REQUEST_METHOD']=='POST'){

//Validation for Username
 $errors = array();
if(empty($_POST['user_name'])){
    $errors['user_name'] = 'Please fill in your Username';//Username
}else{

      $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'")){
        if($check->num_rows){
            $errors['user_name'] = 'Username in use';
        }
    }else{
        $errors['user_name'] = 'the query did not work';
    }


}

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

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




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

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


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

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

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

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

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


//validation for gender column to be selected. 
if(empty($_POST['sex'])){
    $errors['sex'] = 'Please fill in your gender';
}else{

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

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

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


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

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

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








if(empty($errors)){
    $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;    
    }
    else
    {
        $message = 'Registration successfully completed, You can now login';
    }



}}?>

这是html表单:

<!-- 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>

                    <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">

            <br>

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

                            <br>

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

                            <br>

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

                             <br>

                            <label for="EmailInput">Email</label>
                            <input type="email" class="form-control" id="EmailInput" placeholder="jane.doe@example.com" name="email">

                            <br>

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

                            <br>

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

                            <br>

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

                            <br>

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

                             <br>

                            <label for="MaritalStatusInput">Marital Status</label>
                            <select class="form-control" id="MaritalStatusInput" name="mstatus">
                                <option>Single</option>
                                <option>Married</option>
                                <option>Divorced</option>
                                <option>Widowed</option>
                            </select>

                          <br>

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

                            <br>

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

                            <br>

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

                            <br>

                            <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>
                                <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>
                                </optgroup>
                            </select>

                            <br>

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

                            <br>

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

                            <br>

                            <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
            </button>
        </div>
                             </form>

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


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

请注意,php脚本和html形式都在一个文件中。

1 个答案:

答案 0 :(得分:1)

更改training_index.php中的变量名称

$conn and $connection to $conn

因为在connection.php文件中,您将数据库连接变量名称称为

 $con = new mysqli($servername, $username, $password, $dbname);