我对以下代码有问题。变量 $houseid 在第二个 if 语句中显示为空,但可以在第一个中调用。我需要在第二个 if 语句中访问 $houseid 变量。我已经在 if 和第一个之外对其进行了测试,它似乎在两者中都可以正常工作。
$landlordid = $_SESSION['landlordid'];
$con = mysqli_connect("mysql1616int.cp.blacknight.com","***","***","***"); // Connect to the MySQL server
$mysql = mysqli_query($con, "SELECT * FROM houseInfo WHERE landlordID = '{$landlordid}'");
echo '<form method="POST" action=""><select name="pickhouseid">';
while($row = mysqli_fetch_array($mysql)){
echo '<option value="' . $row['houseID'] . '">'. $row['housename'] . '</option>';
}
echo '</select>
<input type="submit" name="houseselect" value="Select">
</form>';
echo "<br>";
$houseid = $_POST['pickhouseid']; ///where house is set.
if(isset($_POST['houseselect'])){
echo "<form method='POST' action=''><select name='services'><option value='gas1'>Gas Reading</option>
<option value='water1'>Water Reading</option><option value='elec1'>Electricity Reading</option>
</select><input type='submit' value='Select'></form>";
echo "<br>";
echo $houseid; /// returns correct value
}
if (($_POST['services']) == 'gas1') {
echo "something";
echo $houseid; ///doesn't work, appears as empty.
}
任何人都可以帮助解决这个问题吗?谢谢你。