-1
好吧我試圖建立一個快速和骯髒的登錄表單,但我繼續得到一個PHP錯誤「警告:mysql_num_rows()期望參數1是資源,null給出在」 我試着環顧四周但似乎沒有任何幫助或工作....php mysql登錄表單
<?php
$user = 'root'; //Database username ("Root for xampp")
$pass = ''; //Database password ("empty for exampp")
$db = 'dragondrivingschooldb'; //Name of database
$con = new mysqli('localhost', $user, $pass, $db) or die("Unable to connect"); //Create new data connection ('name of host/server', user, password, database name)
if(isset($_POST['txtusername']))
{
$username = $_POST['txtusername'];
$password = $_POST['txtpassword'];
$SQL = mysqli_query($con, "SELECT * FROM users WHERE username=' " . $username ." ' AND password= ' " . $password . " ' LIMIT 1 ");
$result = mysqli_fetch_array($SQL);
if (mysql_num_rows($result) == 1)
{
echo "Hello World";
}
else
{
echo "no";
}
}
mysqli_close($con);
?>
<!DOCTYPE html>
<form method="post" action="Login.php">
username: <input type="text" name="txtusername"><br>
password: <input type="text" name="txtpassword"> <br>
<input type="submit" name="submit" value="Login" >
</form>
</html>
改爲使用'mysqli_num_rows($ SQL)',請閱讀文檔:http://www.php.net/manual/en/mysqli-result.num-rows.php#example-1821 - 您必須通過查詢的結果。它不會接受一個數組。可以使用該代碼或「count($ result)」。 – Joe
這意味着您的SQL查詢不返回任何內容。 – DLJ
你在混合MySQL API。這不是朗姆酒和可樂。 –