登录/登录页面bootstrap php

时间:2016-03-02 17:09:42

标签: php

这段代码仍无效。点击它时,提交按钮没有做任何事情。谁能告诉我哪里出错了。因为我刚刚将一些html / css代码更改为bootstrap并且没有更改任何变量或php代码。

<?php
// Assign varibles
$submit = @$_POST['submit'];

//variables to prevent errors
$account = "";
$gender = "";
$name = "";
$email = "";
$password = "";
$password2 = "";
$u_check = "";

//reg form
$account = strip_tags(@$_POST['account']);
$gender = strip_tags(@$_POST['gender']);
$fullname = strip_tags(@$_POST['fullname']);
$email = strip_tags(@$_POST['email']);
$password = strip_tags(@$_POST['password']);
$password2 = strip_tags(@$_POST['password2']);


// will insert the data when the user presses the submit button.
// query will insert data into the database.
if ($submit){
    //check if user email already exists
    $u_check = mysqli_query ($connect,"SELECT email FROM users WHERE email ='$email' ");
    // count the amount of rows where e-mail = $email

    $check = mysqli_num_rows($u_check);
    if ($check == 0) {
        //all fields have been filled in
    if ($account&&$gender&&$name&&$email&&$password&&$password2){
        //if (!empty($account) && !empty($gender) && !empty($name) && !empty($email) && !empty($password) && !empty($password2)){
        //Password Match
    if ($password==$password2) {
        //Validation to check the max length of name is 25 characters 
    if (strlen($name)>25) {
    echo "You have exceed the max characters length for your name.";
    }
else 
{
    //check length of password - cant be more than 25 and less than 6 characters.
    if(strlen($password)>25 ||strlen($password)<6) {
        echo "You password has to be between 6 and 25 characters long";
    }
    else {  
    //encrypt password 
    $password = md5($password);
    $password2 = md5($password2);

    //insert registeration data on the DB
    $reg_query = mysqli_query ($connect, "INSERT INTO users VALUES ('','$fullname','$email','$gender','$password','$password2','','$account','no','')");
    die("<h3>Welcome to MyAstonSpace</h3>Login to your account to get started...");
        }
        }
        }
    else {
        echo "Your passwords do not match. Try Again!";
    }
    }
    else {
        echo "Please complete all the form to register.";
        }
    }
    else {
        echo "E-mail already registered. Try Again!";
    }
        }

?>



    <div class="container" style="position:absolute; top: 175px; left: 400px; ">
    <div class="row-fluid">
        <div class="col-md-12">
            <div class="col-md-6">
                <div class="area">

                        <div class="heading">
                            <h1>Sign Up</h1>
                        </div>
<br/>

                        <form action="#" method="POST" enctype="multipart/form-data" >
                         <div class="controls"  style="font-size:16px">
                            <center>

                             <label class="radio-inline">
                             <input type="radio" name="account"> Student</label>
                             <label class="radio-inline">
                             <input type="radio" name="account"> Landlord
                             </label>
                            </center>
                        </div>
<br/>

                        <div class="controls" style="font-size:16px">
                    <center>

                        <label class="radio-inline">
                        <input type="radio" name="gender"> Male</label>
                        <label class="radio-inline">
                        <input type="radio" name="gender"> Female</label>
                        </form>
                    </center>
  </div>

<br/>

                <div class="form-group">
                <label for = "fullname"> Full Name: </label>
                <input type="text" name="fullname" class="form-control" required/> <br/>


                <label for = "email"> Email: </label>
                <input type="email" name="email" class="form-control" pattern="[A-Za-z0-9._%+-]+@aston.ac.uk" required/> <br/>


               <label for = "password"> Password: </label>
               <input type="text" name="password" class="form-control" required/><br/><br/>

               <label for = "password2"> Retype Password: </label> 
               <input type="text" name="password2" class="form-control"  required/><br/><br/>
              </div>
             By clicking Sign Up, you agree on our <a href="#">terms and condition</a>. <br/><br/>  

             <input type="submit" class="btn btn-sucess" name="submit" value="Sign Up" style="background-color:#337AB7; color:white;">

             </form>     
        </div>      
     </div>
 </div>

2 个答案:

答案 0 :(得分:0)

已编辑的答案(因为OP说提交按钮本身无效)

我找到了什么错误的东西,附上了表格标签,这是不合适的,所以纠正html。

<div class="container" style="position:absolute; top: 175px; left: 400px; ">
    <form action="#" method="POST" enctype="multipart/form-data" >
        <div class="row-fluid">
            <div class="col-md-12">
                <div class="area">
                    <div class="heading">
                        <h1>Sign Up</h1>
                    </div>
                    <div class="controls" style="font-size:16px">
                        <center>
                            <label class="radio-inline"><input type="radio" name="account"> Student</label>
                            <label class="radio-inline"><input type="radio" name="account"> Landlord</label>
                        </center>
                    </div>
                    <div class="controls" style="font-size:16px">
                        <center>
                            <label class="radio-inline"><input type="radio" name="gender"> Male</label>
                            <label class="radio-inline"><input type="radio" name="gender"> Female</label>
                        </center>
                    </div>
                    <div class="form-group">
                        <label for = "fullname"> Full Name: </label>
                        <input type="text" name="fullname" class="form-control" required/> <br/>
                        <label for = "email"> Email: </label>
                        <input type="email" name="email" class="form-control" pattern="[A-Za-z0-9._%+-]+@aston.ac.uk" required/> <br/>
                        <label for = "password"> Password: </label>
                        <input type="text" name="password" class="form-control" required/><br/><br/>
                        <label for = "password2"> Retype Password: </label> 
                        <input type="text" name="password2" class="form-control"  required/><br/><br/>
                    </div>
                    By clicking Sign Up, you agree on our <a href="#">terms and condition</a>. <br/><br/>
                    <input type="submit" class="btn btn-sucess" name="submit" value="Sign Up" style="background-color:#337AB7; color:white;">
                </div>
            </div>
        </div>
    </form>
</div>

上一个答案(根据OP,未达到以下条件而产生)

 if ($account&&$gender&&$name&&$email&&$password&&$password2){

上述条件不允许继续,根据我的理解,您试图在此处验证表单元素以不允许空值。 因此,只需添加一个简单的关键字empty来更改条件,该关键字检查值是NULL还是NOT NULL

if (!empty($account) && !empty($gender) && !empty($name) && !empty($email) && !empty($password) && !empty($password2)){

上述条件将检查非NULL值。

答案 1 :(得分:0)

<div class="container" style="position:absolute; top: 175px; left: 400px; ">
    <form action="#" method="POST" enctype="multipart/form-data" >
        <div class="row-fluid">
            <div class="col-md-12">
                <div class="area">
                    <div class="heading">
                        <h1>Sign Up</h1>
                    </div>
                    <div class="controls" style="font-size:16px">
                        <center>
                            <label class="radio-inline"><input type="radio" name="account" value="student"> Student</label>
                            <label class="radio-inline"><input type="radio" name="account" value="landlord"> Landlord</label>
                        </center>
                    </div>
                    <div class="controls" style="font-size:16px">
                        <center>
                            <label class="radio-inline"><input type="radio" name="gender" value="male"> Male</label>
                            <label class="radio-inline"><input type="radio" name="gender" value="female"> Female</label>
                        </center>
                    </div>
                    <div class="form-group">
                        <label for = "fullname"> Full Name: </label>
                        <input type="text" name="fullname" class="form-control" required/> <br/>
                        <label for = "email"> Email: </label>
                        <input type="email" name="email" class="form-control" pattern="[A-Za-z0-9._%+-]+@aston.ac.uk" required/> <br/>
                        <label for = "password"> Password: </label>
                        <input type="text" name="password" class="form-control" required/><br/><br/>
                        <label for = "password2"> Retype Password: </label> 
                        <input type="text" name="password2" class="form-control"  required/><br/><br/>
                    </div>
                    By clicking Sign Up, you agree on our <a href="#">terms and condition</a>. <br/><br/>
                    <input type="submit" class="btn btn-sucess" name="submit" value="Sign Up" style="background-color:#337AB7; color:white;">
                </div>
            </div>
        </div>
    </form>
</div>

按标记正确格式化html标记,当您有单选按钮时,需要为其添加value属性。例如。 <label class="radio-inline"><input type="radio" name="account" value="student"> Student</label>我在这里添加了value="student"

因此你的PHP提交就是这样的。

function controlUnwantedTags($getString) {
    //if anything else to be done, do here.
    return strip_tags($getString);
}

$errorMessages      = array();
if(isset($_POST["submit"])) {
    $account        = controlUnwantedTags($_POST["account"]);
    $gender         = controlUnwantedTags($_POST["gender"]);
    $fullname       = controlUnwantedTags($_POST["fullname"]);
    $email          = controlUnwantedTags($_POST["email"]);
    $password       = controlUnwantedTags($_POST["password"]);
    $password2      = controlUnwantedTags($_POST["password2"]);

    if($account=="") {
        $errorMessages[]    = "Missed Selecting Account Type";
    }
    if($gender=="") {
        $errorMessages[]    = "Missed Selecting Gender";
    }
    if($fullname=="") {
        $errorMessages[]    = "Missed Entering Name";
    }
    if($email=="") {
        $errorMessages[]    = "Missed Entering E-Mail";
    }
    else {
        //even check the correct email format
        //validate your email here, in case if it is unique everytime
    }
    if($password=="") {
        $errorMessages[]    = "Missed Entering Password";
    }
    else {
        //validate if you have some pattern match for password
    }
    if($password2=="") {
        $errorMessages[]    = "Missed Re-Entering Password";
    }
    if($password!="" and $password2!="" and $password!=$password2) {
        $errorMessages[]    = "Password Entered doesn't match, Please Re-enter.";
    }
    if(count($errorMessages)==0) {
        //database insertion goes here

        //redirect to your required page
    }
}

if(count($errorMessages)!=0) {
    echo "Could not proceed due to following reasons.<br />";
    echo implode("<br />", $errorMessages);
}