我正在努力从我的数据库中进行选择并将其添加到 a$_SESSION
以继续到个人资料页面。
请注意,“ $_SESSION['user'] = $email;
”在个人资料上有效并打印,但我确信那是因为它已经提出了我的表格。
连接.php
<?php
session_start();
$required = array('email', 'password');
// Loop over field names, make sure each one exists and is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
die("All fields are required.");
} else {
//CHECK POINT 1
$con = mysql_connect("**HOST**", "**DB**", "**PASSWORD**");
mysql_select_db("**DB**")or die("cannot select DB");
// username and password sent from form
$email=$_POST['email'];
$psswrd=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$email = stripslashes($email);
$psswrd = stripslashes($psswrd);
$email = mysql_real_escape_string($email);
$psswrd = mysql_real_escape_string($psswrd);
$sql="SELECT * FROM **Table WHERE email='$email' and password='$psswrd'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
//fetch info & create session
$id="SELECT 'id' FROM **table**";
$_SESSION['user'] = $email;
$_SESSION['uid'] = $id;
$_SESSION['name1'] = $fname;
配置文件.php
<?php
session_start();
$email = $_SESSION["user"];
$id = $_SESSION["uid"];
$fname = $_SESSION["name1"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>...</head>
<body>
<div align=center><font color="#000000" face="Bodoni MT" class="ws12"><?php echo "I am ". $id. ". Contact me at ". $email ?></font></div>
</body>
</html>