-2

我将如何进行这项工作,我之前问过但没有得到正确的答案。这段代码是用户登录,所以当他们登录时,我希望用户名和头像可以通过站点进行跟踪。到目前为止,我只有用户名。我尝试过方法,但每次都失败了。

$username = $_POST['username'];
$password = sha1($_POST['password']);
$sql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = mysqli_query($conn, $sql) or die('Error querying database.');
$count=mysqli_num_rows($result);

if ($count == 1) 
{
   $row = mysqli_fetch_array($result);
   while ($_SESSION['username'] = $row['username'])
   {
      session_start();
      header('Location: index.php'); 
   }
}
else
{
   echo 'Invalid Logins';
}

mysqli_close($conn);
?>
4

1 回答 1

2

假设您将头像存储在avatar数据库的字段中:

if ($count == 1) 
{
    session_start();

    $row = mysqli_fetch_array($result);
    $_SESSION['username'] = $row['username'];
    $_SESSION['avatar'] = $row['avatar'];

    header('Location: index.php'); 
}
else
{
    echo 'Invalid Logins';
}
于 2012-05-25T04:13:32.127 回答