提交表单时出错(php& bootstrap) [英] Errors while submitting the form ( php & bootstrap)

查看:200
本文介绍了提交表单时出错(php& bootstrap)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



目前我正面临问题与注册。



这是错误

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



这是php脚本:

 <?php 
//连接到数据库
包括( 'connection.php');
$ b $ if($ _SERVER ['REQUEST_METHOD'] =='POST'){

//验证用户名
$ errors = array();
if(empty($ _ POST ['user_name'])){
$ errors ['user_name'] ='请填写您的用户名'; //用户名
} else {

$ user_name = mysqli_real_escape_string($ con,trim($ _ POST ['user_name']));
//验证以检查发布的用户名是否正在使用中。
if($ check = $ connection-> query(SELECT * FROM student WHERE username ='$ user_name')){
if($ check-> num_rows){
$ errors ['user_name'] ='用户名';
}
} else {
$ errors ['user_name'] ='查询无效';




$ b //验证密码
if(empty($ _ POST ['pword'])){
$ errors ['pword'] ='请填写密码';
} else {
$ pword = $ _POST ['pword'];

//检查密码是否与密码字段匹配
if(empty($ _ POST ['pwordConfirm'])){
$ errors ['' pwordConfirm'] ='请验证密码';
} else {
$ pwordConfirm = $ _POST ['pwordConfirm'];

if($ pword!= $ pwordConfirm){
$ errors ['pwordConfirm'] ='密码不匹配';
} else {
$ password = mysqli_real_escape_string($ connection,trim($ _ POST ['pword']));
// $ password = sha1($ password);





$ b //验证名称textfield
if(empty($ _ POST ['fname' ])){
$ errors ['fname'] ='请填写您的名字';
} else {
$ fname = mysqli_real_escape_string($ connection,trim($ _ POST ['customer_name']));

$ b $ //验证护照textfield
if(empty($ _ POST ['passport'])){
$ errors ['passport'] ='请填写你的护照';
} else {
$ passport = mysqli_real_escape_string($ connection,trim($ _ POST ['passport']));


$ b //验证电子邮件
if(empty($ _ POST ['email'])){
$ errors ['email' ] ='请填写您的电子邮件';
} else {
$ email = mysqli_real_escape_string($ connection,trim($ _ POST ['email']));
$ b $ if($ check = $ connection-> query(SELECT * FROM customer WHERE email ='$ email')){
if($ check-> num_rows){
$ errors ['email'] ='电子邮件正在使用';
}
} else {
$ errors ['email'] ='查询无效';



//验证手机否
if(empty($ _ POST ['mobinput'])){
$ errors ['' mobinput'] ='请填写您的电话';
} else {
$ mobinput = mysqli_real_escape_string($ connection,trim($ _ POST ['mobinput']));

$ b $ //验证手机否
if(empty($ _ POST ['homemobinput'])){
$ errors ['homemobinput'] ='请填写您的电话';
} else {
$ homemobinput = mysqli_real_escape_string($ connection,trim($ _ POST ['homemobinput']));

$ b $ //验证手机否
if(empty($ _ POST ['dob'])){
$ errors ['dob'] ='请填写您的电话';
} else {
$ dob = mysqli_real_escape_string($ connection,trim($ _ POST ['dob']));
}


//验证要选择的性别列。
if(empty($ _ POST ['sex'])){
$ errors ['sex'] ='请填写您的性别';
} else {

if($ _POST ['sex'] =='default')
{
$ errors ['sex'] ='请选择你的性别';
}
else {
$ gender = mysqli_real_escape_string($ connection,trim($ _ POST ['sex']));



//验证mstatus
if(empty($ _ POST ['mstatus'])){
$ errors ['mstatus '] ='请填写您的电话';
} else {
$ mstatus = mysqli_real_escape_string($ connection,trim($ _ POST ['mstatus']));


//验证教育
if(empty($ _ POST ['education'])){
$ errors ['education'] ='请填写你的手机';
} else {
$ education = mysqli_real_escape_string($ connection,trim($ _ POST ['education']));

//验证职业
if(空($ _ POST ['职业'])){
$ errors ['职业'] ='请填写您的手机;
} else {
$职业= mysqli_real_escape_string($连接,trim($ _ POST ['职业']));


$ b $ //验证地址
if(empty($ _ POST ['address'])){
$ errors ['address' ] ='请填写您的地址';
} else {
$ address = mysqli_real_escape_string($ connection,trim($ _ POST ['address']));


//验证wmcauin
if(empty($ _ POST ['wmcauin'])){
$ errors ['wmcauin'] ='请填写你的手机';
} else {
$ wmcauin = mysqli_real_escape_string($ connection,trim($ _ POST ['wmcauin']));

//验证tp
if(empty($ _ POST ['tp'])){
$ errors ['tp'] ='请填写您的手机;
} else {
$ tp = mysqli_real_escape_string($ connection,trim($ _ POST ['tp']));

//验证wauinmassage
if(空($ _ POST ['wauinmassage'])){
$ errors ['wauinmassage'] ='请填写您的手机;
} else {
$ wauinmassage = mysqli_real_escape_string($ connection,trim($ _ POST ['wauinmassage']));


//验证hduhabttbc
if(empty($ _ POST ['hduhabttc'])){
$ errors ['hduhabttc'] ='请填写你的手机';
} else {
$ hduhabttbc = mysqli_real_escape_string($ connection,trim($ _ POST ['hduhabttc']));









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','$职业','$ education','$ wauinmassage','$ hduhabttbc',
'','$ tp','$ wmcauin', '$ sex','$ user_name','$ password','S');

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

$ b $ 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 ='注册成功完成,您现在可以登录';
}



}}?>

这是html表单:

 <! -  PopUp注册表单 - > 
< div id =signupclass =modal faderole =dialog>
< div class =modal-dialog>

<! - PopUp注册表单内容 - >
< div class =modal-content>
< div class =modal-header>
< button type =buttonclass =closedata-dismiss =modal>& times;< / button>
< h4 class =modal-title>按摩课程注册表< / h4>
< / div>

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

< label for =usernameInputclass =usernameinput>用户名< / label>
< input type =textclass =form-controlid =user_namename =user_name>

< br>

< label for =passwordinput>密码< / label>
< input type =passwordclass =form-controlid =passwordinputname =pword>

< br>

< br>
< label for =NameInput>名称< / label>
< input type =textclass =form-controlid =InputNameplaceholder =Jane Doename =fname>

< br>

< label for =ICinput> I.C / Passport No.< / label>
< input type =textclass =form-controlid =ICinputname =passport>

< br>

< label for =EmailInput>电子邮件< / label>
< input type =emailclass =form-controlid =EmailInputplaceholder =jane.doe@example.comname =email>

< br>

< label for =mobinput>手机号码< / label>
< input type =number_formatclass =form-controlid =mobinputname =mobinput>

< br>

< label for =homemobinput>主页否< / label>
< input type =number_formatclass =form-controlid =homemobinputname =homemobinput>

< br>

< label for =DOBinput>出生日期< / label>
< input type =dateclass =form-controlid =DOBinputname =dob>

< br>

< label for =SexInput> sex< / label>
< select class =form-controlid =SexInputname =sex>
< option>男性< / option>
< option>女性< / option>
< / select>

< br>

< label for =MaritalStatusInput>婚姻状态< / label>
< select class =form-controlid =MaritalStatusInputname =mstatus>
< option>单一< / option>
< option>已婚< / option>
< option>离婚< / option>
< option>丧偶< / option>
< / select>

< br>

< label for =EducationInput>教育< / label>
< input type =textclass =form-controlid =EducationInputname =education>

< br>

< label for =OccupationInput>职业< / label>
< input type =textclass =form-controlid =OccupationInputname =occupation>

< br>

< label for =Addressinput>地址< / label>
< input type =textclass =form-controlid =Addressinputname =address>

< br>

< label for =CourseSelection>您对哪种按摩课程感兴趣?< / label>
< select class =form-control selectpickerid =CourseSelectionname =wmcauin>
< optgroup label =专业人员>
< option>全身按摩< / option>
< option>足疗课程< / option>
< option>芳香疗法课程< / option>
< / optgroup>
< optgroup label =高级>
< option>产前和产后< / option>
<选项>减肥按摩< /选项>
< option>淋巴引流< / option>
<选项>水疗和面部护理< /选项>
< option>雨滴技巧< / option>
< option>男性健康< /选项>
< option>运动损伤< / option>
< option>传统马来< / option>
< / optgroup>
< / select>

< br>

< label for =TrainerPreferenceInput>培训师偏好< / label>
< select class =form-controlid =TrainerPreferenceInputname =tp>
< option>男教练< / option>
< option>女教练< / option>
< / select>

< br>

< label for =InterestFeedbackInput>为什么您在Massage中被认识?< / label>
< input type =textclass =form-controlid =InterestFeedbackname =wauinmassage>

< br>

< label for =ReferalFeedbackInput>您是如何知道Tim BodyCare培训中心的< / label>
< input type =textclass =form-controlid =ReferalFeedbackInputname =hduhabttbc>
< div class =form-group>
< button type =submitclass =btn btn-primaryname =btn-signup>
< i class =glyphicon glyphicon-open-file>< / i>  SIGN UP
< / button>
< / div>
< / form>

< div class =modal-footer>
< p>通过点击提交,即表示您同意我们的条款和条件< / p>


< / div>
< / div>
< / div>
< / div>
<! - PopUp注册结束表单 - >




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



解决方案

更改training_index.php中的变量名称

  $ conn和$ connection to $ conn 

因为在connection.php文件中你提到了你的数据库连接变量名称为

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


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:

<?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';
    }



}}?>

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>

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

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

解决方案

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);

这篇关于提交表单时出错(php&amp; bootstrap)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆