我得到一個錯誤 - >sqlsrv_num_rows()預計參數1是資源
誰能弄清楚什麼是錯與編碼,香港專業教育學院一直在努力3小時,現在 由於事先:)sqlsrv_num_rows()預計參數1是資源
<?php
include("config.php");
username and password sent from form
$myusername=htmlspecialchars($_POST[username]);
$mypassword=htmlspecialchars($_POST[password]);
$sql="SELECT * FROM Login WHERE Username=$myusername and
Password=$mypassword";
$result=sqlsrv_query($conn,$sql);
$count=sqlsrv_num_rows($result);
if($count==1){
header("location: something");
}
else {
echo "Wrong Username or Password";
}
?>
CONFIG.PHP
<?php
$serverName = '';
$uid = '';
$pwd = '';
$databaseName = '';
$connectionInfo = array("UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$databaseName);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
}
?>
'$ result'可能是錯誤的,這意味着你的查詢失敗了,如果這實際上是你的SQL查詢的話,這似乎很可能。 –
可能重複的[SQLSRV \ _NUM \ _ROWS錯誤](https://stackoverflow.com/questions/22858327/sqlsrv-num-rows-error) – alalp