-1

i want to develop a web page containing two forms.when page loads it just display the first form and after it is filled then the second table display at the demand of user and both forms values will be stored in 2 different tables in database.i dont know what's the logic behind that. plz suggest me solution and examples link.thankyou before this is my code just for display one form but the second has the same pattern

 <!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">
<?php 
if (!empty($_POST['det_loc'])) {
   //do something here;
   mysql_connect("localhost","root");//database connection
mysql_select_db("admin");

//inserting data into DET_LOCATION Table
$locID=$_POST["LocID"];
$latitude=$_POST["Latitude"];
$longitude=$_POST["Longitude"];
$store = "INSERT INTO det_location(LocID,Latitude,Longitude) VALUES('$locID','$latitude','$longitude')";
//declare in the order variable
$result = mysql_query($store);  //order executes
if($result)
{
    echo "<br>Input data is succeed";

} else{
    echo "<br>Input data is fail";
}
}

if (!empty($_POST['more_loc'])) {
   //do something here;
   mysql_connect("localhost","root");//database connection
    mysql_select_db("admin");

//inserting data into DET_LOCATION Table
$latitude=$_POST["Latitude"];
$longitude=$_POST["Longitude"];
$store = "INSERT INTO det_location(Latitude,Longitude) VALUES('$latitude','$longitude')";
//declare in the order variable
$result = mysql_query($store);  //order executes
if($result)
{
    echo "<br>All data is Entered";

} else{
    echo "<br>Input data is fail";
}
}
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Input Detail Location</title>
</head>

<body>
<table border="1">
  <tr>
    <td align="center">Det_Location</td>
  </tr>
  <tr>
    <td>
      <table>
        <form method="post" action="det_loc">
    <tr>
          <td>locID</td>
          <td><input type="Integer" name ="LocID" size="20">
          </td>
        </tr>
    <tr>
          <td>Latitude</td>
          <td><input type="Float" name ="Latitude" size="20">
          </td>
        </tr>
                <tr>
          <td>Longitude</td>
          <td><input type="Float" name="Longitude" size="20">
          </td>
        </tr>
          </form>
      </table>

    </td>
  </tr>
  <tr>
  <td>
 <input type="submit" name="det_loc" value="Add more" />
 </td>
  </tr>
  </table>

  <table border="1">
  <tr>
    <td align="center">More Locations</td>
  </tr>
  <tr>
    <td>

    <table>
        <form method="post" action="">
    <tr>
          <td>Latitude</td>
          <td><input type="Float" name ="Latitude" size="20">
          </td>
        </tr>
                <tr>
          <td>Longitude</td>
          <td><input type="Float" name="Longitude" size="20">
          </td>
        </tr>
        <tr>
          <td>Latitude</td>
          <td><input type="Float" name ="Latitude" size="20">
          </td>
        </tr>
                <tr>
          <td>Longitude</td>
          <td><input type="Float" name="Longitude" size="20">
          </td>
        </tr>
          </form>
        </table>

      </td>
    </tr>
     <tr>
    <td>
    <input type="submit" name="more_loc" value="Send Data" />
     </td>
        </tr>
</table>
 </td>
  </tr>
  </table>

</body>
  • but it display both tables on the same page and doesnt send data to the mysql database.

4

1 回答 1

3

这取决于您何时希望隐藏表单。如果您想用 PHP 隐藏它们,则应在将表单发送给用户之前完成。否则,您将需要 javascript,或者将多个请求发送到您的服务器。

你想要达到的目标就像“用枪打子弹,希望当子弹到一半的时候,你把枪指向下方,子弹也会掉下来”。不会发生。这是不可能的。如果您希望在客户端发生更改,则需要在客户端进行一些更改。

于 2013-04-03T19:50:03.717 回答