0

在下面的php脚本中,当给出正确的un和pass时,它会显示Welcome。但是当我们给出错误的pass时,如代码所示,它不会输出“错误的用户名密码组合”。这是什么原因?

<?php
$query = mysql_query($sql);
if (!$query)
{
    echo 'Invalid query: ' . mysql_error() . "\n";
    die($message);
}
if (mysql_fetch_assoc($query))
{
    $query = mysql_query($sql);
    $row   = mysql_fetch_assoc($query);
    if ($row['un'] == $un && $row['pd'] == $encpass)
    {
        echo "<h1>WellCome</h1>";
        echo '<br /><a href="home.php?' . SID . '">page 2</a>';
        echo $row['un'];
    }
    else
    {
        echo "Wrong user name password combination";
    }
}
?>
4

2 回答 2

2

$由于您在select中检查了正确的密码,如果密码错误,将不会提取任何行,因此您不会在mysql_fetch_assoc之后输入代码。

尝试

if($row = mysql_fetch_assoc($query)) {
  echo "<h1>WellCome</h1>";
  echo '<br /><a href="home.php?' . SID . '">page 2</a>';
  echo $row['un'];
} else {
  echo "Wrong user name password combination";
}
于 2013-06-26T10:00:08.673 回答
2

尝试

...
if(mysql_fetch_assoc($query)) {
$query = mysql_query($sql);
$row = mysql_fetch_assoc($query);
if($row['un'] == $un && $row['pd'] == $encpass) {
    echo "<h1>WellCome</h1>";
    echo '<br /><a href="home.php?' . SID . '">page 2</a>';
    echo $row['un'];
} else
    echo "Wrong user name password combination";
} else
echo "Wrong user name password combination";
...
于 2013-06-26T10:02:17.280 回答