我的表名-我的表列
fname lname email password
我想通过电子邮件id或密码使用会话从表中获取fname。我想在登录后在另一个页面上显示fname。请帮帮我。
session_start();
$cser = mysqli_connect("localhost", "root", "", "srptech") or die("connection failed:" . mysqli_error());
if (isset($_REQUEST['login'])) {
$c = $_REQUEST['fname'];
$a = $_REQUEST['email'];
$b = $_REQUEST['password'];
$res = mysqli_query($cser, "select fname from persons where email='$a'and password='$b'");
while ($row = mysql_fetch_array($res)) {
$fname = $row['fname'];
$_SESSION["user-name"] = $fname;
}
$result = mysqli_num_rows($res);
if ($result == true) {
$_SESSION["login"] = "1";
$_SESSION["email-id"] = $a;
header("location:my-account.php");
exit();
session_write_close();
} else {
header("location:index.php?err=1");
}
}
还有另一个页面-my-account.php
session_start();
if (!isset($_SESSION["login"])) // $_SESSION is a variable and login is a SESSION name
{
header("location:index.php");
} else {
echo 'Welcome' . '<h3>' . $_SESSION["email-id"] . '</h3>';
echo 'Welcome' . '<h3>' . $_SESSION["user-name"] . '</h3>';
}
电子邮件在另一页上是echo,但fname不显示(echo) Error- Invalid user-name.
如何在另一页上回显fname?请帮帮我。
1条答案
按热度按时间fae0ux8s1#
我更新了你的脚本,现在可以不使用sql注入了