我查找了许多不同的存储会话变量的方法,但似乎无法找到为什么我的会话变量没有从我的下拉菜单中存储。这是我的campaign_select.php 代码,然后在按下提交按钮后转到store_select.php。
<?php
session_start ();
$host="localhost"; // Host name
$username="sxx2"; // Mysql username
$password="xxxxx!"; // Mysql password
$db_name="sxxxxx"; // Database name
$tbl_name="campaign"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query = "SELECT campaignname FROM campaign";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
$dd .= "<option value='{$row['campaignID']}'>{$row['campaignname']}</option>";
}
if ($_POST['Submit'])
{
if(isset($_POST['campaignname']))
{
$_SESSION['campaign']=$_POST['campaignName'];
}
}
$_SESSION['test']="bye";
?>
<form action="store_select.php" method="post">
<select name="campaignName" id="campaignname"><? echo $dd; ?></select>
<input name="Submit" type="submit" value="Submit">
</form>
这里是 store_select.php:
<?php
session_start();
$host="localhost"; // Host name
$username="sxxxx2"; // Mysql username
$password="Wxxxx1!"; // Mysql password
$db_name="xxxx2"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$campaign=$_SESSION['campaign'];
echo $_SESSION['campaign'];
echo $_SESSION['test'];
$query = "SELECT storename FROM stores WHERE campaignname='$campaign'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
$dd .= "<option value='{$row['storeID']}'>{$row['storename']}</option>";
}
?>
<form action="" method="post">
<select name="stores"><? echo $dd; ?></select>
</form>