我是 php 新手,想问一下如何访问另一个页面上的变量。 我的代码:
<?php
$username = "ADMIN";
$host = "localhost";
$password = "ADMIN";
$database = "USER";
$sname = $_POST['signupname'];
$susername = $_POST['susername'];
$spassword = $_POST['spassword'];
$gender = $_POST['gender'];
$con = mysqli_connect($host, $username, $password, $database);
if(isset($_POST["signup"])) {
mysqli_query($con, "INSERT INTO `USER`.`INFO` (`UID`, `NAME`, `USERNAME`, `PASSWORD`, `GENDER`, `BDAY`, `BMONTH`, `BYEAR`, `STATUS`, `LAST-ACTIVE`) VALUES (NULL, '$sname', '$susername', '$spassword', '$gender', '', '', '', '', NULL);");
echo "<script type='text/javascript'>window.location.replace('../SSTEPS1010101/birthdaycheck1010101.php');</script>";
}
?>
以及其他页面代码:-
<?php
require '../SIGNUP/connects1010101.php';
$bday = $_POST["bday"];
$bmonth = $_POST["bmonth"];
$byear = $_POST["byear"];
if (isset($_POST["snext"])) {
mysqli_query($con, "UPDATE `USER`.`INFO` SET `BDAY` = '$bday', `BMONTH` = '$bmonth', `BYEAR` = '$byear' WHERE `info`.`USERNAME` = '$susername;'");
}
echo "$susername";
?>
如何在其他页面访问$susername
?
我正在使用 $_SESSIONS["susername"];并在第一页上回显它并且它正在工作,但在另一页上 $_SESSIONS["susername"];不工作。
最佳答案
1.Use Session:
Fisrt.php
session_start();
$username = "Max";
$username=$_SESSION['username'];
echo $username; //Output: Max
在另一个页面中使用
session_start();
echo $_SESSION['username']; //Output: Max
- include
可以,但是最后一个包含中的变量将覆盖第一个包含中的变量:
myfirstfile.php
$name = 'max';
mysecondfile.php
$city = 'xyz';
test.php
include 'myfirstfile.php';
echo $name;
include 'mysecondfile.php';
echo $city;
输出:
max
xyz
关于php - 如何访问另一个页面上的mysql变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44089734/