-1

好的,我有这个代码:

<?//admin
$host = 'localhost'; // Host name Normally 'LocalHost'
$user = 'root'; // MySQL login username
$pass = ''; // MySQL login password
$database = 'juliver'; // Database name
$table = 'admin'; // Members name

mysql_connect($host, $user, $pass);
mysql_select_db($database);
if (isset($_POST['acc']) && ($_POST['pass']))
{
$username = mysql_real_escape_string($_POST['acc']);
$password = hash('sha512', $_POST['pass']);

$result = mysql_query("SELECT * FROM admin WHERE username = '$username' AND password =     '$password'");

if(mysql_num_rows($result))
{
  // Login
echo "has been login";
}
else
{
  // Invalid username/password
  echo 'Error: Invalid username or password';
}

exit;

}
else
{
echo "not been set";
}
?>

我收到了这个错误:“警告:mysql_num_rows() 期望参数 1 是资源,第 17 行的 C:\xampp\htdocs\mu2\admin.php 中给出的布尔值已登录”,这里有人可以帮助我吗请弄清楚那个错误到底是什么?..提前谢谢

无论如何,我对任何建议都持开放态度。

4

3 回答 3

0

您对 mysql_query 的调用很简单,您可以echo mysql_error()在它之后查看错误是什么。

于 2012-04-25T01:15:45.887 回答
0

您的 MySQL 查询有问题,您可能正在访问不存在的内容或拼写错误的内容。回应 mysql_error() 会告诉你你的问题。我还建议消除查询中的额外空格(看起来有点奇怪)。:)

于 2012-04-25T01:18:17.270 回答
0

这将帮助您找到错误

error_reporting(E_ALL);
ini_set('display_errors','On');
$host = 'localhost'; // Host name Normally 'LocalHost'
$user = 'root'; // MySQL login username
$pass = ''; // MySQL login password
$database = 'juliver'; // Database name
$table = 'admin'; // Members name

$link = mysql_connect ( $host, $user, $pass );

if (! $link) {
    die ( 'Could not connect: ' . mysql_error ());
}

$selected = mysql_select_db ( $database );

if (! $selected) {
    die ( 'Can\'t use foo : ' . mysql_error ());
}

if (isset ( $_POST ['acc'] ) && ($_POST ['pass'])) {
    $username = mysql_real_escape_string ( $_POST ['acc'] );
    $password = hash ( 'sha512', $_POST ['pass'] );

    $result = mysql_query ( "SELECT * FROM admin WHERE username = '$username' AND password =  '$password'" );

    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }

    $num_rows = mysql_num_rows($result);

    if ($num_rows > 0) {
        // Login
        echo "has been login";
    } else {
        // Invalid username/password
        echo 'Error: Invalid username or password';
    }

    exit ();

} else {
    echo "not been set";
}
于 2012-04-25T01:38:29.420 回答