我想调用一个变量的值到我的其他php文件,但它不工作。首先,它向我展示了除了新的数据之外的旧数据,但现在它甚至没有获得任何价值。这是我在第一个文件
$_SESSION['tsmUserName']=$username;
做这是我做的第二
$ids=$_SESSION['tsmUserName'];
我竟然用的var_dump,它只是告诉我,tsmusername是不确定的。当我第一次制作程序时一切正常,但后来我将主键更改为用户名,这一切都搞砸了,PHP表单开始使用旧的删除值自动填充输入字段,然后当我将主键更改回它仍然开始显示旧的删除值。重新启动我的计算并再次检查后,它变得更糟,因为现在我得到未定义的错误。这里,r我的两个PHP文件的代码,以防万一:
<?php
$firstnameError = $lastnameError = $usernameError = $passwordError = $birthdateError = $mobileError = $emailError = "";
// Check if data are posted.
if (isset($_POST['submit'])){
$firstname = $lastname = $username = $password = $birthdate = $mobile = $email = "";
$errorOccured = false;
if (isset($_POST['tsmFirstName'])){
$firstname = trim($_POST['tsmFirstName']);
if (strlen($firstname) == 0){
$firstnameError = "First Name is missing";
$errorOccured = true;
}
}
else{
$firstnameError = "First Name is missing";
}
//Checking last name
if (isset($_POST['tsmLastName'])){
$lastname = trim($_POST['tsmLastName']);
if (strlen($lastname) == 0){
$lastnameError = "First Name is missing";
$errorOccured = true;
}
}
else{
$lastnameError = "First Name is missing";
}
//checking the username
if (isset($_POST['tsmUserName'])){
$username = trim($_POST['tsmUserName']);
$usernameLenght = strlen($username);
if ($usernameLenght == 0){
$usernameError = "First Name is missing";
$errorOccured = true;
}
elseif ($usernameLenght < 4){
$usernameError = "Your username should be minimum 4 characters";
$errorOccured = true;
}
}
else{
$usernameError = "First Name is missing";
}
//checking the password
if (isset($_POST['tsmPassword'])){
$password = trim($_POST['tsmPassword']);
if (strlen($password) == 0){
$passwordError = "First Name is missing";
$errorOccured = true;
}
}
else{
$passwordError = "First Name is missing";
}
//checking the birthdate
if (isset($_POST['tsmBirthDate'])){
$birthdate = trim($_POST['tsmBirthDate']);
if (strlen($birthdate) == 0){
$birthdateError = "First Name is missing";
$errorOccured = true;
}
}
else{
$birthdateError = "First Name is missing";
}
// checking the mobile
if (isset($_POST['tsmMobile'])){
$mobile = trim($_POST['tsmMobile']);
if (strlen($mobile) == 0){
$mobileError = "First Name is missing";
$errorOccured = true;
}
}
else{
$mobileError = "Mobile is missing";
}
//checking the email
if (isset($_POST['tsmEmail'])){
$email = trim($_POST['tsmEmail']);
if (strlen($email) == 0){
$emailError = "Email is missing";
$errorOccured = true;
}
}
else{
$emailError = "Email is missing";
}
if(!$errorOccured){
require_once("connection.php");
$_SESSION['tsmUserName']=$username;
$names=$_SESSION['tsmFirstName'];
var_dump($_SESSION);
$keychain= sha1($username);
$my_query="INSERT INTO users (id, firstname, lastname, username, password, birthdate, mobile, email, status, keychain) VALUES (NULL,'$firstname','$lastname','$username','$password','2016-1-1','$mobile','$email','0','$keychain')";
$result=mysqli_query($connection,$my_query);
if($result){
$message_mail = "Dear $firstname, <br> Thank You for registering with us. Click now on the link below to activate your account. <br> $keychain <br><br> Thank You.";
$subject_mail= "Your account has been created";
$to_mail = $email;
$headers[]= 'MIME-Version 1.0';
$headers[]= 'content-type:text/html; charset=utf8';
$headers[]= 'From: [email protected]';
mail($to_mail,$subject_mail,$message_mail,implode("\r\n",$headers));
//after email is sent redirect to thank you page.
header("Location:completed.php?task=done");
exit();
echo 'Thank You';
}
else{
echo "<b> Error unable to post. </b>";
mysqli_error($connection);
}
mysqli_close($connection);
}
}
?>
而且应该从第一个获取用户名,第二个是在这里
<?php
session_start();
$EntryError=$ExitError="";
if (isset($_POST['submit'])){
$entrydate = $exitdate = "";
$errorOccured = false;
if (isset($_POST['tsmdate'])){
$entrydate = trim($_POST['tsmdate']);
if (strlen($entrydate) == 0){
$EntryError = "date is missing";
$errorOccured = true;
}
}
else{
$EntryError = "date is missing";
}
// checking for last name
if (isset($_POST['tsmexit'])){
$exitdate = trim($_POST['tsmexit']);
if (strlen($exitdate) == 0){
$ExitError = "First Name is missing";
$errorOccured = true;
}
}
else{
$ExitError = "last Name is missing";
}
$ids=$_SESSION['tsmUserName'];
var_dump($_SESSION);
if(!$errorOccured){
require_once("connection.php");
$my_query="INSERT INTO timing (`No`, `Entry Date and Time`, `Exit Date and Time`, `Username`) VALUES (NULL,'$EntryError','$exitdate','$ids')";
$result=mysqli_query($connection,$my_query);
if($result)
{
echo 'thank you';
}
else
{
echo 'error';
}
mysqli_close($connection);
}
}
?>
你必须调用'session_start()'在这两个文件 – WillardSolutions
OMG多数民众赞成它..我是这样的我失去了主意!谢谢!!!!!!! –