所以我在下面写了一个很短的代码,希望大家能理解。
这是 login.php 代码
<?php
$session_start();
$_SESSION['uname'] = $_POST['username'];
$pass = $_POST['password'];
$db = mysqli_connect('localhost', 'root','','test');
$res = mysqli_query($db,"SELECT*FROM tb_test WHERE uid='$_SESSION[uname]' AND pass='$pass')";
if($res)
{
<form method="post" action="new_file.php">
<input type="text" name="name" placeholder="Your Name" />
<input type="submit" name="submit" placeholder="Submit" />
</form>
}
?>
这是 new_file.php 代码
$session_start();
$name = $_POST['name']
$db = mysqli_connect('localhost', 'root','','test');
$res = mysqli_query($db,"INSERT INTO tb_test2 (name) VALUES ('$name');
if($res)
{
header('location: login.php');
}
此代码工作正常。但是在重定向到login.php页面后,系统无法识别先前的$ _POST ['username']和$ _POST ['password']。我该如何解决?