-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.

Tayyaba Jan
  • 21
  • 1
  • 7
  • 2
    You have a SQL injection vulnerability. – SLaks Apr 03 '13 at 19:42
  • php can't "hide" anything, unless it just doesn't output the form in the first place. you have PHP output some CSS that could hide the form once it's rendered on the client. either a style directive, or an inline `... style="display: none"`. – Marc B Apr 03 '13 at 19:42
  • [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the red box? Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Apr 03 '13 at 19:43
  • thank you to all. but can you people design a prototype for it. it will help me a lot. – Tayyaba Jan Apr 03 '13 at 19:48
  • Please, he/she want the working code! – Gabriel Santos Apr 03 '13 at 19:49
  • if it is possible through java script then how can i implement through it. – Tayyaba Jan Apr 03 '13 at 19:49
  • Look into JavaScript, or more specifically, AJAX. That'd be the approach I'd take. – Mike Apr 03 '13 at 19:50

1 Answers1

3

It depends when you want the forms to be hidden. If you want them hidden with PHP it should be done before you send the forms to the user. Else you will either need javascript, or have multiple requests sent to your server.

What you are trying to achieve is like "shooting a bullet with a gun and hoping that when it's half way and you point the gun down, the bullet will also go down." Not going to happen. It can't be done. You need something on the client-side if you want changes to occur there.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
Touch
  • 1,481
  • 10
  • 19
  • +1 for the mid-air bullet simile, if nothing else; I may have to "borrow" that one :) – IMSoP Apr 03 '13 at 19:50
  • IMSop definitely :)Mr.Touch, i want to display the first form when user is filled it if he/she want to add some more fields so he/she clicks on a button "Add More" and it display some of fields from the above form.and here the user is just admin. hope you will understand my ques. – Tayyaba Jan Apr 03 '13 at 21:12
  • You mean something similar to how gmail let's you upload 1 attachment and you can click on a link that will load more elements that will allow you to add more attachments but in this case some input? If so, are you familiar with javascript, better yet, jQuery? – Touch Apr 03 '13 at 22:22
  • can you provide some example links for me for better understanding. because i am new to java script and need some examples code to solve my problem. – Tayyaba Jan Apr 05 '13 at 05:04
  • Although some are against it, I find http://w3schools.com useful and coupled with that is some videos to see it in action. http://www.youtube.com/user/thenewboston Just look for the the javascript tutorial playlist. I always find it nice to read something myself and see someone doing it at the same time. – Touch Apr 05 '13 at 09:29