2016-02-27 67 views
-3

我一直在嘗試在PHP中創建登錄系統。 我已經設法成功地連接到數據庫,但我有一個問題說嘗試創建登錄系統時出錯

警告:mysql_num_rows()預計參數1是資源,布爾在C中給出:\ xampp1 \ htdocs中\登錄\檢查.PHP在線23
錯誤的用戶名或密碼是錯誤的 公告:未定義的屬性:mysqli的:: $關閉在C:\ xampp1 \ htdocs中\登錄\ check.php上線36

我的代碼是:

<html> 
<head> 
    <title>Login Page</title> 
</head> 
<body> 
    <form method="post" action="check.php" > 
    <table> 
     <tr> 
     <td><label>Username</label></td> 
     <td><input type="text" name="username"></td> 
     </tr> 
     <tr> 
     <td><label>password</label></td> 
     <td><input type="text" name="password"></td> 
     </tr> 
     <tr> 
     <td><input type="submit" value="submit"></td> 
     </tr> 
    </table> 
    </form> 
</body> 
</html> 

<?php 
ob_start(); 
$username= $_POST['username']; 
$password= $_POST['password']; 

$servername= "localhost"; 
$username= "root"; 
$password = ""; 
$dbname="login"; 

$conn= mysqli_connect($servername,$username,$password,$dbname); 

if (!$conn){ 
    die("Not connected". mysqli_connect_error); 
}else{ 
    echo "connection sucessful"; 

} 

$sql= "select * from details where $username=username and $password=password"; 

$result=mysql_query($sql); 
$count=mysql_num_rows($result); 



if ($count == 1){ 
    header("location:sucess.php"); 
}else{ 
    echo "Wrong username or password are wrong"; 


} 
$conn->close; 
ob_end_flush(); 
+1

在代碼中混合使用'mysqli和mysql' – Saty

+1

再次查看該查詢 – 2016-02-27 13:20:11

+0

username ='$ username'是您正在查找的內容,請閱讀PDO –

回答

0

試試這個SQL:

$sql= "select * from details where username='{$username}' and password='{$password}'"; 
+0

使用column ='value'或列LIKE'value' – Cuchu

0

修正1:$username=username必須username=$username

修正2:

$sql= "select * from details where $username=username and $password=password"; 

$result=mysql_query($sql); 
$count=mysql_num_rows($result); 

必須是:我想你使用預處理語句提示]

$user_name = $username; 
$pwd = $password; 


$query = $conn->prepare("select * from details where username = ? and password = ?"); 

$query->bind_param("ss",$user_name,$pwd); 

if (!$query->execute()) 
{ 
    echo $conn->error; 
} 

$row_cnt = $query->num_rows;