2014-08-27 99 views
-1

警告:mysqli_num_rows()期望參數1爲mysqli_result,布爾值給出 iam無法登錄,並且在給定錯誤之上會被通知,請提出更正。謝謝。 警告:mysqli_num_rows()期望參數1是mysqli_result,布爾給定 iam無法登錄,並且在給定的錯誤之上被通知。建議更正。謝謝。警告:mysqli_num_rows()期望參數1是mysqli_result,布爾給定

<html> 
     <head> 
      <title>Login page</title> 
     </head> 
      <style type='text/css'> 
       body{ 
         background:url('Login.jpg'); 
        } 
      </style> 
     <body> 
      <form method ='post' action='login.php'> 
       <table width='400' border='5' align='center'> 
        <tr> 
         <td colspan='5' align='center'><h1><font color="MediumBlue">Login form</h1></font> 
         </td> 

        </tr> 
        <tr> 
         <td><font color='DarkOrange'>email</font> 
         </td> 
         <td><input type='text' name='email'/></td> 
        </tr> 
        <tr> 
         <td><font color='DarkOrange'>Password</font></td> 
         <td><input type='password' name='pass'/></td> 
        </tr> 
        <tr> 
         <td colspan='5' align='center'><input type='submit' name='login' value='login'/> </td> 
        </tr> 
      </form> 

         <font color="LightSalmon"><h2><p style="position: fixed; bottom: 50%; width:100%; text-align: center"> Not registered yet?<a href='registration.php'>Sign up here</a> 
       </p><h2></font> 




     </body> 
    </html> 
<?php 
    $connection=mysqli_connect("localhost","root","","user_db"); 
    if(isset($_POST['login'])){ 
    $user_Email=$_POST['email']; 
    $user_password=$_POST['pass']; 

if($user_Email==''){ 
echo "<script>alert('please enter your email')</script>"; 
exit(); 
} 

if($user_password==''){ 
echo "<script>alert('please enter your password')</script>"; 
exit(); 
} 
    $check_user="select * from users where user_email =='$user_Email' AND user_password =='$user_password'"; 
    $result= mysqli_query($connection,$check_user); 
    $count=mysqli_num_rows($result); 
    if ($count==1) 
    { 

    echo"<script>window.open('welcome.php','_blank')</script>"; 

    } 
    else{ 
    echo"<script>alert('username or password is incorrect')</script>"; 
    } 
    } 

    ?> 
+0

在查詢中將==更改爲= – 2014-08-27 22:33:24

+0

已經諮詢了我在下面給出的答案嗎? – 2014-08-30 14:31:08

回答

5

變化user_email =='$user_Email' AND user_password =='$user_password'兩個==單打=

user_email ='$user_Email' AND user_password ='$user_password'


在問候密碼存儲。你似乎在使用純文本; 不。如果您打算與此同時進行現場活動,那麼只是時間問題才能被黑客入侵,真的是。使用CRYPT_BLOWFISH或PHP 5.5的password_hash()函數。對於PHP < 5.5使用password_hash() compatibility pack


另外,use prepared statements,或PDO with prepared statements他們安全

就目前而言,您現在的代碼可以使用SQL injection

+0

旁註:我沒有看到發佈的評論,正在忙於輸入答案。 – 2014-08-27 22:34:00

+0

@Rudie正確。我在過去6個月裏看到過很多關於它的問題。 – 2014-08-27 22:39:25

0

也許你應該檢查mysqli_query()是否在失敗的情況下不返回false,例如:如果有空結果。

相關問題