2016-03-21 56 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