gpt4 book ai didi

php - 重新加载后页面变成空白

转载 作者:行者123 更新时间:2023-11-29 23:59:30 25 4
gpt4 key购买 nike

无法理解重新加载成员(member)页面(登录后)后页面变成空白。但所有其他事情都工作正常。

下面是登录表单页面后login_execution.php页面的代码

<?php

session_start();
$con=mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('loged', $con);
if(isset($_POST["submit"])) {
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password=md5($password);
$sql="SELECT username FROM list WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);


if($count==1)
{
session_regenerate_id();
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
session_write_close();
echo "<table>
<tr>
<th>username</th>";



$row = mysql_fetch_array($result)

?>
<tr style="background-color:blue;color:white;">
<td><font size="6"><?php echo $row['username']; ?></font></td>
<h1 align="center"><font size="6" color="blue">welcome <?php echo $row['username']; ?></font></h1>
<p align="right"><font size="4" color="#380B61"><a href="logout.php">Logout</a></font></td>





</tr>
<?php


echo "</table>";
}

else
{
?>
<h1 align="center"><font size="4" color="red">enter coerrect username and password</font></h1>
<td><a href="login.php">BACK</a></td>
<?php
}
}
?>

最佳答案

您的条件是,如果在重新加载页面时单击提交,则不会单击提交按钮,因此不会显示任何内容。

要纠正此问题,请使用以下代码。

<?php

session_start();
$con=mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('loged', $con);
if(isset($_POST["submit"])) {
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
$password=md5($password);
$sql="SELECT username FROM list WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count==1)
{
$row = mysql_fetch_array($result)
session_regenerate_id();
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['name'] = $row['username'];
session_write_close();
}
}


if(isset($_SESSION['username']))
{
echo "<table>
<tr>
<th>username</th>";





?>
<tr style="background-color:blue;color:white;">
<td><font size="6"><?php echo $row['username']; ?></font></td>
<h1 align="center"><font size="6" color="blue">welcome <?php echo $_SESSION['name']; ?></font></h1>
<p align="right"><font size="4" color="#380B61"><a href="logout.php">Logout</a></font></td>





</tr>
<?php


echo "</table>";
}

else
{
?>
<h1 align="center"><font size="4" color="red">enter coerrect username and password</font></h1>
<td><a href="login.php">BACK</a></td>
<?php
}
?>

关于php - 重新加载后页面变成空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25138350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com