我是PHP新手,用户表单有问题。代码执行并生成带有选择框和提交按钮的页面。提交按钮应该提示一个新的php文件。但是,新PHP文件中的代码未被执行。我只是得到一个空白的网页。
<?php
include 'Connection.php';
echo "<form action=\"accountStatusChange.php\" method=\"post\">";
echo "<br/>";
echo "<select name=\"accountStatus\">";
echo "<option value=\"Active\">Active</option>";
echo "<option value=\"Inactive\">Inactive</option>";
echo "</select>";
echo "<input type=\"submit\" name=\"loadAccountStatus\" value=\"Go\"/>";
echo "</form>";
?>
这是文件accountStatusChange.php:
<html><body>
<?php
$status = $_POST['accountStatus'];
echo $status;
?>
</body></html>
答案 0 :(得分:0)
首先,让您的生活更轻松,尝试将代码更改为:
<?php
include 'Connection.php';
echo '
<form action="accountStatusChange.php" method="post">
<br/>
<select name="accountStatus">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
<input type="submit" name="loadAccountStatus" value="Go"/>
</form>
';
?>
然后在第二个文件中:
<html><body>
<?php
if(isset($_POST['accountStatus'])){
$status = $_POST['accountStatus'];
echo $status;
}else{
echo 'form not submitted';
}
?>
</body></html>
答案 1 :(得分:0)
尝试使用$_REQUEST
;像这样:
$status = $_REQUEST['accountStatus'];
<?php
include 'Connection.php';
?>
<form action="accountStatusChange.php" method="post">
<br/>
<select name="accountStatus">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
<input type="submit" name="loadAccountStatus" value="Go"/>
</form>