2017-09-17 116 views
-1

我有一個註冊表格,它有一個密碼字段和一個確認密碼字段。我想密碼和確認密碼字段是相同的,所以它可以註冊新的用戶信息。以註冊形式確認密碼

形式:

<form class="form-signin" name="Register_Form" method="post" action="regcheck.php"> 
    <h2 class="form-signin-heading">Please sign in</h2> 
    <label for="inputPassword" class="sr-only">Password</label> 
    <input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required> 
    <label for="CPassword" class="sr-only">Confirm Password</label> 
    <input type="password" id="CPassword" name="CPassword" class="form-control" placeholder="Confirm Password" required> 

    <button class="btn btn-lg btn-primary btn-block" type="reg" name="reg" value="Register">Register</button> 
    </form> 

      require_once 'connect.php'; 
      if (isset($_POST['reg'])){ 
         //$dob = $_POST['date']; 
         $dob = date('Y-m-d', strtotime($_POST['date'])); 
         $Student_ID = $_POST['Student_ID']; 
         $gender = $_POST['gender']; 
         $course = $_POST['Course']; 
         $email = $_POST['inputEmail']; 
         $password = $_POST['inputPassword']; 
         $cpassword = $_POST['CPassword']; 
         $FN = $_POST['FirstName']; 
         $SN = $_POST['SecondName']; 

         if ($password === $cpassword) { 
          // success! 
          $sql = "INSERT INTO tblaccounts (Email, Password, Student_ID, FirstName, SecondName, Course, Gender, DoB) VALUES ('".$email."','".$password."','".$Student_ID."','".$FN."','".$SN."','".$course."','".$gender."','".$dob."')"; 
          $result = mysqli_query($connection, $sql) or die("Database Connection Failed" . mysqli_error($connection)); 
          //$count = mysqli_num_rows($result); 
          echo "Registeration Successful!:"; 

          header('Location: login.php'); 
          } 
          else { 
           // failed :(
          } 


      } else { 
         echo "Registeration Failed!:";# 
         ?><br/><a href ="login.php">Go back to the login screen.</a><?php 
        } 
+0

這段代碼會發生什麼?你開放SQL注入,參數化。您還需要散列密碼,不要存儲純文本密碼。 – chris85

+0

@ chris85我想讓表單按照我的意願去做。然後,我將致力於安全性等工作。 – helloworld999

+0

你的問題是關於這個條件,如果($密碼=== $ cpassword){',不工作,對不對?它做什麼,拋出一個錯誤,永遠不匹配,總是匹配,其他? – chris85

回答

-1

我不知道理解你的問題,其實你的代碼似乎(在粗暴的方式)來實現自己的目標。但是,由於您已經向客戶端發送了信息,因此您的腳本在使用header()重定向到login.php時將失敗。當您在用於顯示錶單域的同一腳本中處理數據時會發生這種情況。我建議您將表單的數據發送到另一個腳本。

+0

我不明白你在做什麼。 – helloworld999

+0

注意:未定義索引:CPassword – helloworld999

+0

這不提供問題的答案。一旦你有足夠的[聲譽](https://stackoverflow.com/help/whats-reputation),你將可以[對任何帖子發表評論](https://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 - [來自評論](/ review/low-quality-posts/17360707) –