我基本上是PHP的初学者。我对此有基本的了解,但真的很难找到解决方案。
主页.php:
<?php
require('dbconnection.php');
if(isset($_POST)&&(sizeof($_POST)>0))
{
$sql_query_insert_user = "insert into users(user_fname,user_mname,user_lname,user_dob,user_email,user_doc,user_gender,user_nationality) values '$fname','$mname','$lname','$dob','$email','$doc','$gender','$nationality')";
mysql_query($sql_query_insert_user,$dbconnect) or die("cannot insert to user");
$user_id = mysql_insert_id();
session_start();
$_SESSION['user_id'] = $user_id;
$_SESSION['user_name'] = $user_name;
$sql_query_insert_user_login = "insert into users_login(user_id,user_name,user_password) values ('$user_id','$user_name','$user_password')";
mysql_query($sql_query_insert_user_login,$dbconnect) or die("cannot connect to user login");
}
?>
我尝试像这样访问会话变量:
用户主页.php
<?php
session_start();
echo $_SESSION['id'];
echo $_SESSION['user_name'];
?>
它显示:
注意:未定义索引:id 注意:未定义索引:user_name
关于这个错误的任何想法?我花了很长时间试图找出问题所在。