输出未通过$ 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>
答案 0 :(得分:1)
我注意到的第一件事是你的echo
语句超出了你定义$userInfo
的范围。第二个是你在$userInfo
循环的每次传递中分配while
。解决这两个问题:
//beginning of code; session_start, error_reporting, include;
$userInfo = '';
//in the while loop:
$userInfo .= //... whatever it is
请注意,这基本上是马特试图获得的。
答案 1 :(得分:0)
我注意到的第一件事是你在回复它之前没有向$ userInfo附加任何内容 - 你只是覆盖了变量的值。
试试这个,看看是否有帮助:
$userInfo = "";
.
.
.
$userInfo .= "<table>...</table>";
.
.
.
<?php echo $userInfo; ?>