Php 如何在$\u POST[]中传递参数?

Php 如何在$\u POST[]中传递参数?,php,forms,action,Php,Forms,Action,我有一个名为main.php的文件,其中有一个表单,表单的操作是另一个php文件,即brand.php。这意味着,在main.php文件中提交表单后,brand.php文件将作为操作启动。 main.php文件的表单部分如下:- <form action="brand.php" method="POST"> <input type="submit" value="Brand Name" id="b1" name="brand_button"> </form&g

我有一个名为main.php的文件,其中有一个表单,表单的操作是另一个php文件,即brand.php。这意味着,在main.php文件中提交表单后,brand.php文件将作为操作启动。

main.php文件的表单部分如下:-

 <form action="brand.php" method="POST">
 <input type="submit" value="Brand Name" id="b1" name="brand_button">
 </form>
echo "<form action='size.php' method='POST'>";
while($row = $result->fetch_assoc()) 
{


    echo "<input type='submit' name=".$row["brand"]." value=" .   $row["brand"] . " style='height:20px;width:100px'>";

    echo '<br>';
    echo '<br>';
    $count=$count+1;
}
echo "</form>";
$db=new mysqli('localhost',$user,$pass,$db) or die("Abhra...unable");
if($db->connect_error)
{
     echo "Unable to connect"; 
}

$bname=$_POST[];

echo '<br>';
$q1= "select DISTINCT size from garments where brand='.$bname.'";
$result=$db->query($q1);
if ($result->num_rows > 0) 
{

     $count=1;
     echo "<form action='size.php' method='POST'>";
     while($row = $result->fetch_assoc()) 
     {


          echo "<input type='submit' name=.$count. value=" . $row["size"] . " style='height:20px;width:100px'>";

       echo '<br>';
       echo '<br>';
       $count=$count+1;
     }
     echo "</form>";
} 

$db->close();
?>


现在brand.php文件的表单部分在这里:-

 <form action="brand.php" method="POST">
 <input type="submit" value="Brand Name" id="b1" name="brand_button">
 </form>
echo "<form action='size.php' method='POST'>";
while($row = $result->fetch_assoc()) 
{


    echo "<input type='submit' name=".$row["brand"]." value=" .   $row["brand"] . " style='height:20px;width:100px'>";

    echo '<br>';
    echo '<br>';
    $count=$count+1;
}
echo "</form>";
$db=new mysqli('localhost',$user,$pass,$db) or die("Abhra...unable");
if($db->connect_error)
{
     echo "Unable to connect"; 
}

$bname=$_POST[];

echo '<br>';
$q1= "select DISTINCT size from garments where brand='.$bname.'";
$result=$db->query($q1);
if ($result->num_rows > 0) 
{

     $count=1;
     echo "<form action='size.php' method='POST'>";
     while($row = $result->fetch_assoc()) 
     {


          echo "<input type='submit' name=.$count. value=" . $row["size"] . " style='height:20px;width:100px'>";

       echo '<br>';
       echo '<br>';
       $count=$count+1;
     }
     echo "</form>";
} 

$db->close();
?>
echo”“;
而($row=$result->fetch_assoc())
{
回声“;
回声“
”; 回声“
”; $count=$count+1; } 回声“;

现在实际的问题是每次在brand.php文件的循环中提交时,我都需要触发另一个php文件,即size.php。

size.php文件的代码如下:-

$db=new mysqli('localhost',$user,$pass,$db) or die("Abhra...unable");
if($db->connect_error)
{
     echo "Unable to connect"; 
}

$bname=$_POST[];

echo '<br>';
$q1= "select DISTINCT size from garments where brand='.$bname.'";
$result=$db->query($q1);
if ($result->num_rows > 0) 
{

     $count=1;
     echo "<form action='size.php' method='POST'>";
     while($row = $result->fetch_assoc()) 
     {


          echo "<input type='submit' name=.$count. value=" . $row["size"] . " style='height:20px;width:100px'>";

       echo '<br>';
       echo '<br>';
       $count=$count+1;
     }
     echo "</form>";
} 

$db->close();
?>
$db=newmysqli('localhost',$user,$pass,$db)或die(“Abhra…无法”);
如果($db->connect\u错误)
{
回显“无法连接”;
}
$bname=$_POST[];
回声“
”; $q1=“选择不同于品牌服装的尺码。$B名称。”; $result=$db->query($q1); 如果($result->num_rows>0) { $count=1; 回声“; 而($row=$result->fetch_assoc()) { 回声“; 回声“
”; 回声“
”; $count=$count+1; } 回声“; } $db->close(); ?>


现在我怀疑在size.php文件的第7行中,$_POST[]的参数是什么,特别是在调用页面中,按钮的相应名称部分也是一个查询字符串$row[“brand”]。

在您当前的工作方式中,有两个明显的问题:

  • main.php
    生成的HTML页面提交
    brand_按钮
    数据,该数据在
    brand.php
    脚本中可用,但在
    size.php
    脚本中不可用
    您可以通过(在
    brand.php
    中)生成类似

    两个问题,为什么每次循环都需要启动它?为什么在循环中反复使用相同名称的输入?实际上我需要创建一个树型查询结构,,,,单击品牌按钮后,可用品牌名称将显示为按钮。然后单击此类按钮后,该特定品牌的可用大小将再次显示为按钮,依此类推,,,只需为brand.php中的提交按钮指定一个固定名称–无需通过按钮名称传输品牌,既然你已经把它放进了按钮值中,那么树型的意思是这样的吗?此查询是否受到来自用户的某种信息的影响?为什么不在更改完成后预计算查询并将其自动导出到json文件?(如果你可以避免去db,那总是更好)不,不,不:1)你只需要一个
    按钮,2)你需要一个
    元素-这不是“type=submit”-作为你的_POST[]变量。看这里:或者你能详细说明一下技巧吗?我也遇到了同样的问题。我也需要size.php页面中的品牌按钮数据,,,但我没有在那里获得数据。@Abhradip不确定在要求详细说明该技术时,您的意思是什么。在您发布的代码中,您只需:1)在
    brand.php
    中添加一行
    echo'如上文第一点所述(例如,
    echo''后面的第二行;)
    ;2) 在size.php中更改
    $bname
    矫揉造作,如上面第2点所述。只有这样,一切都应该按预期进行。尽管如此,我可能错过了一些东西:请随意询问它是否仍然失败。