2016-03-02 352 views
-3

这段代码仍然无法正常工作。提交按钮没有做任何事情,当我点击它。有人可以告诉我我哪里出了问题。因为我只是改变了一些HTML/CSS代码引导,并没有改变任何变量或PHP代码。登录/登录页面引导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._%+-][email protected]" 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> 

回答

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._%+-][email protected]" 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); 
} 
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._%+-][email protected]" 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它检查以便改变的条件下,该值是NULLNOT NULL

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

上述条件将检查不是NULL值。

+0

这段代码仍然不起作用。提交按钮没有做任何事情,当我点击它。有人可以告诉我我哪里出了问题。因为我只是改变了一些HTML/CSS代码引导,并没有改变任何变量或PHP代码。 –

+0

hi @ Aman.V,你的意思是说php没有问题?问题是与HTML/CSS! – ameenulla0007

+0

您之前提到过,它需要您每次输出('请填写所有表格以进行注册')。 – ameenulla0007