在php中检索同一网页上所选下拉项的值,并使用其他数据将其发布到其他表单

在php中检索同一网页上所选下拉项的值,并使用其他数据将其发布到其他表单,php,javascript,mysql,Php,Javascript,Mysql,我正在创建一个具有许多动态下拉列表的表单。。 在第一个下拉列表中选择的值将传递给下一个,并根据该值向数据库发起查询,下一个下拉列表将填充数据。。这个过程在这里进行了四次 为了获得下拉列表中选择的值,我使用javascript函数提交表单,将表单操作保留为空 现在,当我得到所有的值时,我必须将这些信息保存到数据库中,我需要将这些值传递到下一个表单,但由于我的表单操作为空,它只会重新加载页面 <?php include('config.php'); ?> <!DOCTYPE htm

我正在创建一个具有许多动态下拉列表的表单。。 在第一个下拉列表中选择的值将传递给下一个,并根据该值向数据库发起查询,下一个下拉列表将填充数据。。这个过程在这里进行了四次

为了获得下拉列表中选择的值,我使用javascript函数提交表单,将表单操作保留为空

现在,当我得到所有的值时,我必须将这些信息保存到数据库中,我需要将这些值传递到下一个表单,但由于我的表单操作为空,它只会重新加载页面

<?php
include('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function showproduct(product_name)
{
    document.frm.submit();
}
</script>
<script language="javascript" type="text/javascript">
function showpacking(batch_no)
{
    document.frm.submit();
}
</script>
<script language="javascript" type="text/javascript">
function showprice(packing)
{
    document.frm.submit();
}
</script>
</head>

<body>

<form action="" method="post" name="frm" id="frm">
<table width="500" border="0">
  <tr>
    <td width="119">Product Name</td>
    <td width="371">
    <select name="product_name" id="product_name" onChange="showproduct(this.value);">
    <option value="">--Select--</option>
    <?php
     $sql1="select distinct product_name from fertilizer";
    $sql_row1=mysql_query($sql1);
    while($sql_res1=mysql_fetch_assoc($sql_row1))
    {
    ?>
    <option value="<?php echo $sql_res1["product_name"]; ?>" <?php if($sql_res1["product_name"]==$_REQUEST["product_name"]) { echo "Selected"; } ?>><?php echo $sql_res1["product_name"]; ?></option>
     <?php
     }
     ?>
    </select>
    </td>
    </tr>
    <tr>
    <td>Batch No</td>
    <td id="batch">
    <select name="batch_no" id="batch_no" onChange="showpacking(this.value);">
    <option value="">--Select--</option>
    <?php
    $sql="select distinct batch_no from fertilizer where product_name='$_REQUEST[product_name]'";
    $sql_row=mysql_query($sql);
    while($sql_res=mysql_fetch_assoc($sql_row))
    {
    ?>
    <option value="<?php echo $sql_res["batch_no"]; ?>" <?php if($sql_res["batch_no"]==$_REQUEST["batch_no"]) { echo "Selected"; } ?>><?php echo $sql_res["batch_no"]; ?></option>
    <?php
    }
    ?>
    </select>
    </td>
  </tr>

   <tr>
    <td>Packing</td>
    <td id="packing">
    <select name="packing" id="packing" onChange="showprice(this.value);">
    <option value="">--Select--</option>
    <?php
    $sql2="select distinct packing from fertilizer where product_name='$_REQUEST[product_name]' and batch_no='$_REQUEST[batch_no]'";
    $sql_row=mysql_query($sql2);
    while($sql_res2=mysql_fetch_assoc($sql_row))
    {
    ?>
    <option value="<?php echo $sql_res2["packing"]; ?>" <?php if($sql_res2["packing"]==$_REQUEST["packing"]) { echo "Selected"; } ?>><?php echo $sql_res2["packing"]; ?></option>

    <?php
    }
    ?>
    </select>
    </td>
  </tr>

   <tr>
    <td>price per unit</td>
    <td id="price">


    <?php
    $sql3="select distinct rate_per_unit from fertilizer where product_name='$_REQUEST[product_name]' and batch_no='$_REQUEST[batch_no]' and packing=$_REQUEST[packing]";
    $sql_row=mysql_query($sql3);
    while($sql_res3=mysql_fetch_assoc($sql_row))
    {
    ?>
    <input type="text "name="price" id="price" value="<?php echo $sql_res3["rate_per_unit"]; ?>" >
    <?php
    }
    ?>
    </td>
  </tr>


   <tr>
    <td>
    <input type="submit" name="Save" value="save">
    </td>
  </tr>

  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
索罗斯:

示例如下:

我的继任者是请在创建帖子之前使用

注意:给出的示例与您的要求类似

Soruce:

示例如下:

我的继任者是请在创建帖子之前使用

注意:给出的示例与您的要求类似

更换

<input type="submit" name="Save" value="save">
比如:

<input type="button" name="Save" value="Save" 
onclick="
document.getElementById('frm').action = 'next_form.php' ;
document.getElementById('frm').submit();
"/>
替换

<input type="submit" name="Save" value="save">
比如:

<input type="button" name="Save" value="Save" 
onclick="
document.getElementById('frm').action = 'next_form.php' ;
document.getElementById('frm').submit();
"/>