2014-02-23 120 views
0

我對PHP比較陌生,但我知道一些。我試圖做一個登錄系統,但登錄功能似乎並沒有工作。我正在做一個檢查行命令,並檢查它是否= 1,但它是說它不= = 1。 「警告:mysql_num_rows()期望參數1是資源,在C:\ xampp中給出的對象\ htdocs \ message \ login.php 25行「PHP/SQL登錄表單問題

我知道這是因爲它沒有找到匹配的值,但我檢查了數據庫,用戶名和密碼肯定在那裏。

任何幫助將不勝感激。

代碼如下:

<html> 

<head> 

<title>Login - Messaging</title> 

</head> 

<body> 
<?php include "connect.php"; ?> 
<?php include "functions.php"; ?> 
<?php include "header.php"; ?> 

<div> 
<form method="post"> 
<?php 
if(isset($_POST['submit'])){ 
$username=$_POST['username']; 
$password=$_POST['password']; 
if($username === '' || $password === ''){ 
    $message="One or more of the fields are empty"; 
} else { 
    $password1=md5(hash("sha512",$password)); 
    $checklogin = mysqli_query($con,"SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password1'"); 
    $check2=mysql_num_rows($checklogin); 
    if($check2==1){ 
     $message="Successful!"; 
     header("location: index.php"); 
    } else { 
     $message="Incorrect Username or Password"; 
    } 
} 
echo "<p>$message</p>"; 
} 
?> 
Username: <input type="text" name="username" /><br> 
Password: <input type="password" name="password" /><br> 
<input type="submit" name="submit" value="Login" /> 
</form> 
</div> 

</body> 

</html> 
+0

我是你mysqli_和mysql_之間切換? – j08691

+0

混合mysql_ *與mysql_i * –

+0

這似乎是我所做的。 – poseidon

回答

1

你有混合mysql_*mysql_i*,你需要檢查查詢錯誤。

改變這些行:

$checklogin = mysqli_query($con,"SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password1'"); 
$check2=mysql_num_rows($checklogin); 

到:

$checklogin = mysqli_query($con,"SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password1'") or die(mysqli_error($con)); 
$check2=mysqli_num_rows($checklogin); 
+0

非常感謝,效果很好! – poseidon

+0

@poseidon:if if works then then my answer :) –

+0

對不起,我只是,直到問題發佈10分鐘後纔回復,因爲你回答的太快了(再次感謝!:D)讓我接受! – poseidon