Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php:Form返回表单_Php_Forms - Fatal编程技术网

Php:Form返回表单

Php:Form返回表单,php,forms,Php,Forms,我有一个单选按钮表单,它为每个特定选项返回特定类型的表单。我从第二个数据库中获取的数据将用于在数据库中搜索。 我的问题是,如果我在第二个表单中提交数据时对这两个表单都使用post方法,我会注意到我没有对第一个表单执行相同的操作,因为每次加载页面时,我的代码都会验证变量是否为空。我可以在PHP中做些什么,这样服务器将区分表单,而不会在每次通过post提交数据时进行检查?我试着给提交按钮命名,但似乎不起作用。 在数据库中搜索的代码被写入另一个文件,并且正在运行。 提前谢谢 <!doctype

我有一个单选按钮表单,它为每个特定选项返回特定类型的表单。我从第二个数据库中获取的数据将用于在数据库中搜索。 我的问题是,如果我在第二个表单中提交数据时对这两个表单都使用post方法,我会注意到我没有对第一个表单执行相同的操作,因为每次加载页面时,我的代码都会验证变量是否为空。我可以在PHP中做些什么,这样服务器将区分表单,而不会在每次通过post提交数据时进行检查?我试着给提交按钮命名,但似乎不起作用。 在数据库中搜索的代码被写入另一个文件,并且正在运行。 提前谢谢

<!doctype html>
<html>
<body>
<?php
// define variables and set to empty values
$optiuneErr="";
$optiune="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{

   if (empty($_POST["optiune"]))
     {$optiuneErr= "Selectati optiunea";}
   else
     {$optiune = test_input($_POST["optiune"]);}
}
?>
<?php
$numeErr=$anErr=$regiuneErr=$succesorErr=$predecesorErr="";
$nume=$an=$regiune=$succesor=$predecesor="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{

    if (empty($_POST["nume"]))
     {$numeErr= "Introduceti numele";}
   else
     {$nume = test_input($_POST["nume"]);}
     if (empty($_POST["an"]))
     {$anErr = "Introduceti anul";}
   else
     {$an = test_input($_POST["an"]);}
     if (empty($_POST["regiune"]))
     {$regiuneErr = "Introduceti regiunea";}
   else
     {$regiune = test_input($_POST["regiune"]);}
     if (empty($_POST["succesor"]))
     {$succesorErr = "Introduceti succesorul";}
   else
     {$succesor = test_input($_POST["succesor"]);}
     if (empty($_POST["predecesor"]))
     {$predecesorErr = "Introduceti predecesorul";}
   else
     {$predecesor = test_input($_POST["predecesor"]);}
}
function test_input($data)
{
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
}
?>
<p><span class="error">* Selectati un camp.</span></p>
<form method="post" > 
<input type="radio" name="optiune" value="1" />Cauta dupa nume <br />
<input type="radio" name="optiune" value="2" />Cauta dupa an<br />
<input type="radio" name="optiune" value="3" />Cauta dupa regiune<br />
<input type="radio" name="optiune" value="4" />Cauta dupa succesor<br />
<input type="radio" name="optiune" value="5" />Cauta dupa predecesor<br />
<input type="submit" name="submit1" value="Alege" />
<span class="error"> <?php echo $optiuneErr;?></span>
</form>

<?php
switch($optiune)
{
    case 1:
        echo '
        <p><span class="error">* Introduceti o valoare.</span></p>
        <form method="POST">
        Nume: <input type="text" name="nume"><br>
        <input type="submit" value="Cauta" />
        <span class="error"> <?php echo $numeErr;?></span>
        </form>';
        break;
    case 2:
        echo '
        <p><span class="error">* Introduceti o valoare.</span></p>
        <form method="POST" >
        An: <input type="text" name="an"><br>
        <input type="submit" value="Cauta" />
        <span class="error"> <?php echo $anErr;?></span>
        </form>';
        break;
    case 3:
        echo '
        <p><span class="error">* Introduceti o valoare.</span></p>
        <form method="POST">
        Regiune: <input type="text" name="regiune"><br>
        <input type="submit" value="Cauta" />
        <span class="error"> <?php echo $regiuneErr;?></span>
        </form>';
        break;
    case 4:
        echo '
        <p><span class="error">* Introduceti o valoare.</span></p>
        <form method="POST">
        Succesor: <input type="text" name="succesor"><br>
        <input type="submit" value="Cauta" />
        <span class="error"> <?php echo $succesorErr;?></span>
        </form>';
        break;
    case 5:
        echo '
        <p><span class="error">* Introduceti o valoare.</span></p>
        <form method="POST">
        Predecesor: <input type="text" name="predecesor"><br>
        <input type="submit" value="Cauta" />
        <span class="error"> <?php echo $predecesorErr;?></span>
        </form>';
        break;
}
?>
</body>
</html>

*选择联合国营地

双核尾
杜帕尾
区域尾部
成功的尾部
双尾前驱体

您应该使用isset()函数

if (isset($_POST['submit1']))
{

if (empty($_POST["optiune"]))
 {$optiuneErr= "Selectati optiunea";}
else
 {
    if(isset($_PoST['nume']))
    {
       $nume = test_input($_POST["nume"]);
    }
    else if($_POST['an'])
    {
      ///////some checking code/////
    }

    ////and so on for all individual forms///
  }
}

就像第二张表格一样。

谢谢,它似乎起作用了。问题是我没有收到通知,当我提交第二张表格时,没有任何数据。如果我做了一些更改,请看一看