如果post field为空,则运行另一个脚本

时间:2014-07-18 16:15:59

标签: php if-statement

这是我的代码:

<?php
$code = $_POST["code"];
if (!isset($_POST['submit'])) {
?>

<form method="post" action="<?php echo $PHP_SELF;?>">
Code:<input type="text" name="code"><br />
<input type="submit" value="submit" name="submit">
</form>

<?
} else {
echo "".$code." <br />";
}
?>

我需要改变它,所以当&#34;代码&#34;字段留空,脚本将运行另一个脚本。不知道怎么做,就像在2dn线上设置了语句一样。谢谢!

2 个答案:

答案 0 :(得分:0)

将此位置放在您希望运行其他脚本的位置。

require "otherscript.php"

答案 1 :(得分:0)

<?php
$code = $_POST["code"];
if (!isset($code)) {
// Run another script
}
elseif (!isset($_POST['submit'])) {
?>

<form method="post" action="<?php echo $PHP_SELF;?>">
Code:<input type="text" name="code"><br />
<input type="submit" value="submit" name="submit">
</form>

<?
} else {
echo "".$code." <br />";
}
?>

Here您可以阅读有关if / elseif / else语句的更多信息。