我一直在嘗試使這個登錄表單。所有mySQL都是正確的,它連接到數據庫,登錄詳細信息在輸入時是正確的,但是我收到了PHP的錯誤和我的日誌詳細信息錯誤的消息。我是PHP/mySQL的新手,所以我不知道自己做錯了什麼!mySQL和PHP登錄頁面問題
Code for the page that connects to the database.
從PHP錯誤:警告:mysql_num_rows()預計參數1是資源,在/home/bluecode/public_html/intranet/checklogin.php空給出在第22行
表單中的變量是myusername和mypassword。
謝謝:)
<?php
// username and password sent from form
$username=stripslashes($_POST['myusername']);
$password=sha1(stripslashes($_POST['mypassword']));
$host="localhost"; // Host name
$username="bluecode_power"; // Mysql username
$password="bluecode123"; // Mysql password
$db_name="bluecode_login"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$id", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select databse");
$sql="SELECT * FROM `members` WHERE myusername=='$username' and mypassword=='$password'";
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
if($myusername == admin){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
我不認爲你可以過濾瓦特/ == sql – morissette 2014-10-27 18:49:40
請檢查[mysqli](http://php.net/manual/en/book.mysqli.php),而不是使用現在折舊的mysql。 – Mason8r 2014-10-27 18:49:54
嗯,管理員只需要用戶名登錄? – jeroen 2014-10-27 18:51:52