0

我已经使用这个登录脚本很长时间了,它非常可靠,但现在它已经坏了,让我发疯了。

基本上该脚本只接受第一个 MySQL 行用户登录,登录系统将工作,但只是第一个 SQL 行,它似乎忽略所有行?

global_database.php

<?php 

$dbhost = 'localhost';
$dbuser = 'dealerpa_guest';
$dbpass = 'password_here';



function dbConnect($db='') {
global $dbhost, $dbuser, $dbpass;

$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
       or die('We are currently applying some major patches and fixes to our systems.        Please try again in 10 Minutes.');

if ($db!='' and !@mysql_select_db($db))
    die('We are currently applying some major patches and fixes to our systems. Please try again in 10 Minutes.');

return $dbcnx;
 }


?>

global_restriction.php

<?php

session_start();


include_once 'global_database.php';
include_once 'global_common.php';

$dealerUsername = isset($_POST['dealerUsername']) ? $_POST['dealerUsername'] :      $_SESSION['dealerUsername'];
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];


if(!isset($dealerUsername)) {
?>
<html>
<body>
  <form id="dealerLogin" name="dealerLogin" method="post" action="">
<input name="dealerUsername" type="text" id="dealerUsername" size="15"   class="validate[required] text-input" />

  <input name="pwd" type="password" id="pwd" size="15" class="validate[required] text-input" />

 <input name="submit" id="submit" type="submit" value="Login" class="save-button" />

</form>

<?php

exit;
 }

$_SESSION['dealerUsername'] = $dealerUsername;
$_SESSION['pwd'] = $pwd;

dbConnect("dealerpa_account");
$sql = "SELECT * FROM dealerAccount WHERE dealerUsername = '$dealerUsername' AND    dealerPassword = md5('$pwd')";

$result = mysql_query($sql);
if (!$result) {
error('A database error occurred while checking your '.
    'login details.\\nIf this error persists, please '.
    'contact us.');
}

if (mysql_num_rows($result) == 0) {
unset($_SESSION['dealerUsername']);
unset($_SESSION['pwd']);

?>

<html>
<body>
<p>Display Login page again if password is wrong</p>
</body>
<?php
exit;
}

$dealerUsername = mysql_result($result,0,'dealerUsername');
$dealerID = mysql_result($result,0,'dealerID');
?>

我已经检查了 PHP 设置并注册了全局变量,还有什么我可以尝试的。奇怪的是只有一个用户可以登录。就像脚本没有检查整个表,而只查看第一个 SQL 行。

任何帮助都感激不尽。

4

1 回答 1

0

我想这是因为您的行索引在. 而mysql_result()不是使用mysql_resulttry中设置为 0 mysql_fetch_assoc。它将检索关联数组中的用户信息。希望有帮助。

于 2014-05-20T02:58:02.700 回答