2016-03-21 52 views
-1

我嘗試註冊,頁面給出的數據未輸入消息。我以前用幾乎相同的語法創建了許多頁面,但只有給定的語法不起作用。如果密碼驗證循環進入兩個循環,但在最後一個循環中跳轉到其他位置,我試圖通過查詢輸入數據。幫我糾正我的錯誤。謝謝PHP註冊表格無法正常工作

<?php 
    #start session 
    session_start(); 


    #Database connection here 
    $dbc = mysqli_connect('localhost','root','farmstockexchange','fse') OR die('ERROR :'.mysqli_connect_error()); 


    if (isset($_POST['submitted'])==1) 
    { 


     $username = mysqli_real_escape_string($dbc, $_POST['username']); 
     $email = mysqli_real_escape_string($dbc, $_POST['email']); 
     $password = mysqli_real_escape_string($dbc, $_POST['password']); 
     $passwordv = mysqli_real_escape_string($dbc, $_POST['passwordv']); 


     if ($username && $password && $passwordv) { 



      if ($password == $passwordv) 
      { 




       $q = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', SHA1('$password')"; 
       $r = mysqli_query($dbc, $q); 
       if ($r) 
        { 
         header('location:reg1.php'); 
        } 
        else 
         { 
          echo 'data not entered'; 
         } 
      }//$password == $passwordv 

      else { 
       echo 'password didnt match'; 
        } 


     } // $username && $password && $passwordv 
      else  
       { 
        echo 'please enter some data or error :'.mysqli_error($dbc); 
        echo '<p>'.$q.'</p>'; 
       } 


    <!-- there some problem in this loop --> 

    } 

    ?> 

    <!DOCTYPE html> 
    <html> 
    <head> 
     <title></title> 

     <meta name="viewport" content="width=device-width, initial-scale=1"> 

     <?php include('../config/css.php'); ?> <!-- bootstrap cdn --> 
     <?php include('../config/js.php'); ?> <!-- bootstrap cdn --> 

    </head> 
    <body> 

     <div id="wrap"> 

      <div class="container"> 

       <div class="row"> 

        <div class="col-md-4 col-md-offset-4"> 

         <div class="panel panel-info"> 
          <div class="panel-heading"><strong>Register</strong></div><!-- panel heading--> 
          <div class="panel-body"> 

           <form action="register.php" method="post"><!-- basic registration form--> 

            <div class="form-group"> 
             <label for="username">Username</label> 
             <input type="text" class="form-control" id="username" name="username" placeholder="User name" required> 
            </div> 

            <div class="form-group"> 
             <label for="email">Email address</label> 
             <input type="email" class="form-control" id="email" name="email" placeholder="Email Address" required> 
            </div> 

            <div class="form-group"> 
             <label for="password">Password</label> 


      <input type="password" class="form-control" id="password" name="password" placeholder="Password" required> 
            </div> 

            <div class="form-group"> 
             <label for="passwordv">Password</label> 
             <input type="password" class="form-control" id="passwordv" name="passwordv" placeholder="Password Verification" required 
             > 
            </div> 


            <button type="submit" class="btn btn-primary btn-lg btn-block">Register</button> 
            <input type="hidden" name="submitted" value="1"> 
           </form> 
          </div> <!-- panel body --> 
         </div><!-- panel end --> 
        </div><!-- column end --> 
       </div><!-- row end --> 
      </div><!-- container end --> 
     </div> <!-- wrap end --> 



    </body> 
    </html> 
+0

這會給你BTW假陽性'如果(isset($ _ POST [ '提交'])== 1)'使用隱藏輸入' '並且很可能永遠不會開火。 –

+1

你的錯誤?讓我們看看..真正的逃脫密碼?將密碼保存爲純文本?打開sql注入(真正的轉義字符串不能完全保護你)?我不確定這是什麼,但如果你繼續沿着這條道路前進,你會遇到很多問題。 – icecub

+2

請查閱以下鏈接http://php.net/manual/en/mysqli.error.php和http://php.net/manual/en/function.error-reporting.php 並將其應用於您的代碼。 –

回答

0

您沒有結束SQL變量。 將其更改爲

   $q = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', SHA1('$password'))"; 

你爲得到一個)

+0

即使在結束SQL變量 – Prathameshb7

+0

之後,它仍然向我顯示'數據未輸入消息',請首先添加以下變量:$ password = sha1($ password);然後從sql中刪除sha1並用'$ password'取代它,使用if(!mysqli_query($ dbc,「INSERT INTO user(username,email,password)VALUES('$ username','$ email','$ (「錯誤描述:」。mysqli_error($ con)); } –

+0

謝謝。這工作。你展示的和我已經完成的展示有什麼不同? 我現在正在學習一切,因爲我的大學項目和一個很棒的經驗。 – Prathameshb7