2 つのフォームを含む Web ページを作成したいと考えています。ページが読み込まれると、最初のフォームが表示され、入力が完了すると、ユーザーの要求に応じて 2 番目のテーブルが表示され、両方のフォームの値がデータベース内の 2 つの異なるテーブルに格納されます。その背後にあるロジックが何であるかを知りません。解決策と例を教えてくださいlink.thankyou前に、これは1つのフォームを表示するためだけのコードですが、2番目のフォームは同じパターンです
<!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>
ただし、両方のテーブルを同じページに表示し、mysql データベースにデータを送信しません。