Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In the form I created, I need two fields to be dynamically populated from the database while the other fields will be manually entered and push to the database. I have written a script that is able to accept information from the users through a HTMl form and load it on the postgreSQL table via the php script. I created the form with a dropdown listing and able to pull the data from the postgresql but unfortunately the listing does not fall into the dropdown list, it is showing somewhere else on the form not within the dropdown. I have two separate scripts, one is the html script with the php script used to created the form fields with along with the dropdown listing. The second is just a php script that connects to the database and load information from the form onto the database table when the data is entered and the submit tab is clicked

Please I need to get my php script to dynamically populate my html form by drawing data from the postgresql database.I have made some minor corrections on this script and its still not able to populate the dropdown! can somebody out there help out. thanks

    <html>
    <body>
    <p>
    <form action="dropdown.php" method="post">
    <table width="600" cellpadding= "10" cellspacing="1" border="2">
    <tr align="center" valign="top">
    <td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
    <h3>Input Field Tally Information</h3>
    Select Pipe No:<select name="Pipeno"> 
    Select Wall Thickness: <select name="WallThickness"><br><br>
    Input Joint No:<input type="text" name="jointno"> 
    Input measured Length: <input type="text" name="measuredlength"><br><br>
    Input Serial No:<input type="text" name="serialno"><br><br> 
    <input type="Submit" name="submit" value="Submit">   
    </form>
    <?php
    $PGHOST = "localhost:25376";
    $PGDATABASE = "Pipeline";
    $PGUSER = "postgres";
    $PGPASSWORD = "Casa2009";
    $PGPORT = 5432;
    $db_handle = pg_connect("dbname=$PGDATABASE user=$PGUSER
    password=$PGPASSWORD");
    if ($db_handle) {
    echo 'Connection attempt succeeded.';
    } else {
    echo 'Connection attempt failed.';
    }

   echo "<br />\n";
   $query = 'SELECT * from "fieldtally" '; 
   $result = pg_query($db_handle,$query); 
   while ($row = pg_fetch_row($result))
   {
   print ("<option> $row[0]</option>,<option> $row[1]</option> ");
   } 
  ?>
   </select>
   </body>
   </html>


    <html>
    <body>
    <?php
    $PGHOST = "localhost:25376";
    $PGDATABASE = "Pipeline";
    $PGUSER = "postgres";
    $PGPASSWORD = "Casa2009";
    $PGPORT = 5432;
    $db_handle = pg_connect("dbname=$PGDATABASE user=$PGUSER
    password=$PGPASSWORD");
    if ($db_handle) {
    echo 'Connection attempt succeeded.';
    } else {
    echo 'Connection attempt failed.';
    }
    $jointno = pg_escape_string($_POST['jointno']);
    $measuredlength = pg_escape_string($_POST['measuredlength']);
    $serialno = pg_escape_string($_POST['serialno']); 
    $query = "INSERT INTO fieldtally(jointno,measuredlength,serialno)VALUES   
    ('$jointno','$measuredlength','$serialno')";
    $result = pg_query($query);
    if (!$result) {
    $errormessage = pg_last_error();
    echo "Error with query: " . $errormessage;
    exit();
    }
    printf ("These values were inserted into the database - %s %s    
    %s",$jointno,$measuredlength,$serialno);
    pg_close();
   ?> 
  </body>
 </html>
share|improve this question
    
For starters, your HTML is incorrect. The listing here has nested <select> tags and overlapping form elements. The PHP code that prints the <option> tags needs to be inside the <select> tags, which need to be inside the <form> tags. Once your HTML is correct, I can help you debug your PHP. –  L_Holcombe Oct 15 '12 at 20:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.