输出未通过 $userInfo 中的变量显示。当我使用 print_r($_SESSION) 时,它会出于某种原因在 $userInfo 中显示所有输出。我在最后一页设置了 $_SESSION,我知道它正在工作。当我再次使用 print_r 显示会话信息时,所有变量都显示在 $userInfo 中。
<?php
session_start();
error_reporting (E_ALL ^ E_NOTICE);
include "convenienttomysql.php";
//include "convenientglobal2localhost.php";
if (isset($_SESSION['userId'])) {
$pid = $_SESSION['userId'];
$results = mysql_query("SELECT * FROM register WHERE userId='$pid'")or die(mysql_error());
while($rowp=mysql_fetch_array($results)){
$address1=$rowp['address1'];
$address2=ucfirst($rowp['address2']);
$city=ucfirst($rowp['city']);
$region=$rowp['region'];
$postalCode=$rowp['postalCode'];
$country=$rowp['country'];
$shippingRegion=$rowp['shippingRegion'];
$userInfo='<table id="addressTableOutput">
<tr>
<td colspan="2"id="tableTh"> Address Info</td>
</tr>
<tr>
<td>Address 1:</td><td> '.$address1.'</td>
</tr>
<tr>
<td>Address 2:</td><td> '.$address2.'</td>
</tr>
<tr>
<td>City:</td><td> '.$city.'</td>
</tr>
<tr>
<td> Region:</td><td> '.$region.'</td>
</tr>
<tr>
<td>Postal Code:</td><td> '.$postalCode.'</td>
</tr>
<tr>
<td>Country:</td><td>'.$country.'</td>
</tr><tr>
<td>Shipping Region:</td><td> '.$shippingRegion.'</td>
</tr>
<tr>
<td id="editTd"><a id="edit" href="convenienteditaddress.php">Edit</a></td>
</tr>
</table>';
}
}
$errors= array();
if (isset($_POST['submit'])){
$address1=$_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$region=$_POST['region'];
$postalCode=$_POST['postalCode'];
$country=$_POST['country'];
$shippingRegion=$_POST['shippingRegion'];
$msg_to_user="";
if(empty($address1) || empty($city)|| empty($region)|| empty($country)|| empty($shippingRegion)|| empty($postalCode)){
$errors[] = "<span id='asterisk'>*</span>All fields need to be filled in.<span id='asterisk'>*</span>";
}
else{
if(strlen($postalCode) > 5){
$errors[] ="<span id='asterisk'>*</span>Postal Code length is 5 characters.<span id='asterisk'>*</span>";
}
if(empty($region)){
$errors[]="<span id='asterisk'>*</span>Select a Region.<span id='asterisk'>*</span>";
}
if(empty($shippingRegion)){
$errors[]="<span id='asterisk'>*</span>Select a shipping region.<span id='asterisk'>*</span>";
}
if(strlen($country)< 2){
$errors[]="<span id='asterisk'>*</span>Please enter a country.<span id='asterisk'>*</span>";
}
}
if(!empty($errors)){
foreach($errors as $error){
$msg_to_user2= "$error";
}
}
else{
$check = mysql_query("UPDATE register SET address1='$address1',address2='$address2',city='$city',region='$region',postalCode='$postalCode',country='$country',shippingRegion='$shippingRegion' WHERE userId='$pid'")or die(mysql_error());
}
}
?>
<html>
<body>
<?php echo $userInfo;?>
</body>
</html>