I have updated this script. The dynamic dropdown portion of the script requirement has been achieved with contributions from the good members of this forum. Now I am working on getting some of the fields on the form to auto populate when an item is selected from the dropdown list. For instance if I select pipeno and wallthickiness from my dropdown, I would like to have the corresponding tuples of DJoint, pipeno2, Heatno1 and heatno 2 on the record to automatically populate their various fields in the form from the database The field I am looking to auto-populate are the ones Im echoing in the php scipt but I think something is not very right with my script as I keep getting this error on the last line of the script. I will really appreciate some contributions and help with this issue

Parse error: syntax error, unexpected end of file in C:\Users\imasha\Documents\My Web Sites\Personal Site1\dropdown2.php on line 63

Here is my updated script

        <?php
         // Php Code to connect to postgresqldatabase
         include ("connection.php");

        $query = 'select * from fieldtally order by pipeno asc'; 
        $result = pg_query($db_handle,$query); 
        while ($row = pg_fetch_row($result))
        {

       // Creates Arrays to use in dropdowns
            $pipeno_array[] = $row[0];
            $wallthickness_array[] = $row[1];
        } 

        // Declare dropdown functions for the HTML form
        function dropdown($field_name, $num){

        // Creates the Dropdown
            echo "<select name=\"".$field_name."\" id=\"".$field_name.$num."\"\n";
            echo "<option value=\"\"> --- Select --- </option>\n";
            // Chooses which array to use for Dropdown options
            global $pipeno_array, $wallthickness_array;
            $name_array = ($field_name == 'pipeno') ? $pipeno_array : $wallthickness_array;
            // Creates the Dropdown options based off the array above
            foreach($name_array as $k){
                echo "<option value=\"$k\">$k</option> \n"; }
            // Ends the Dropdown
             echo "</select>\n"; 
             if($field_name == 'pipeno'){
                $wallthickness = 'wallthickness';
                echo $formValue->DJNo($DJno);
                echo $formValue->Heatno1($pipeweight);
                echo $formValue->pipeno2($pipeno2);
                echo $formValue->Heatno2($pipegrade);
        }
        ?>

        <html>
        <head><title>UG Pipeline Fiedl Data Capture</title>
        </head>
        <body>
        <p></p>
        <form action="<?php echo $PHP_SELF; ?>" 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:<?php dropdown('pipeno', 1); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 1); ?><br /><br />

     DJ No:<input type="text" name="jointno" value="<?php $DJno = "jointno"; echo $formValue->DJNo($DJno);?>"> 

    HeatNo1: <input type="text" name="pipeweight" value="<?php $pipeweight = "pipeweight"; echo $formValue->Heatno1($pipeweight); ?>"><br><br>

    pipeno2: <input type="text" name="loadtally" value="<?php $pipeno2 = "loadtally"; echo $formValue->pipeno2($pipeno2);?>"> 

    HeatNo2: <input type="text" name="pipeweight" value="<?php $pipeweight = "pipegrade"; echo $formValue->Heatno2($pipegrade); ?>"><br><br>

    Input Serial No: <input type="text" name="serialno"><br><br> 

    Input measured Length: <input type="text" name="measuredlength"><br><br>

    <input type="Submit" name="submit" value="Submit">

    </td></tr></table>
    </form>

<p>
<form action="fieldbend.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="#ff9d9d">
<h3>Input Field Bend Information</h3>
Select Pipe No:<?php dropdown('pipeno', 2); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 2); ?><br /><br />
Input Measured Distance: <input type="text" name="measureddistance"><br /><br /> Input Bend Angle: <input type="text" name="benddegree"><br><br>
Input Bend Type: <input type="text" name="bendtype"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>

<p>
<form action="apptally.php" method="post">
<table width="600" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#66CC66">
<h3>Input App. Tally Information</h3>
 Input Type: <input type="text" name="type">   Input Serial No: <input type="text" name="serialno"><br><br>
Input Reference ID: <input type="text" name="referenceid"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>
     </body>
    </html>
share|improve this question
    
Shade, since your original question was answered, and this is a new issue, you should do this as a new question, not by editing your first question. First, most users will not see your question, because it has an answer. Second, with a new question/answer both you and the person that helps solve your issue will get rep points, which neither of you will receive by answering this edit. I will be happy to help again, once you post it as a new question. – Sean Oct 17 '12 at 0:19
    
Thanks! I will do just that – Shade Oct 17 '12 at 13:50
up vote 1 down vote accepted

I notice a few issues in your code.

The first one, pointed out by Mauricio, is that your <options></options> are not inside your <select name="education"></select> tags. Also why is your select name education, when the options are $row['pipeno'], and you are getting $_POST['pipeno']?

The second issue is when you are echoing the <options></options>.

//<option> value="<?=$row["pipeno"]; ?>"><?=$row["pipeno"]; ?></option>
        print ("<option> $row[0]</option>");

You are commenting out the <option> opening tag, the value is outside the <option> tag as you already closed it, and it looks like you are echoing each option twice with <option value="<?=$row["pipeno"]; ?>"><?=$row["pipeno"]; ?></option> & print ("<option> $row[0]</option>");

EDIT this is updated to match your edited code in your question

After looking over this again, I think your problem is how you are creating your dropdown. Try putting this at the top, as a function, and then you just call it later wherever you need it. You can then specify if the dropdown is for pipeno or wallthickness and then just specify what # of dropdown, so it can create a unique id.

Try changing the code to-

<?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.';
 }

$query = 'select * from fieldtally order by pipeno asc '; 
$result = pg_query($db_handle,$query); 
while ($row = pg_fetch_row($result))
{
    // Creates Arrays to use in dropdowns
    $pipeno_array[] = $row[0];
    $wallthickness_array[] = $row[1];
} 

 // This function creates dropdowns that can be used in your forms
function dropdown($field_name, $num){
    // Creates the Dropdown
    echo "<select name=\"".$field_name."\" id=\"".$field_name.$num."\"\n";
    echo "<option value=\"\"> --- Select --- </option>\n";
    // Chooses which array to use for Dropdown options
    global $pipeno_array, $wallthickness_array;
    $name_array = ($field_name == 'pipeno') ? $pipeno_array : $wallthickness_array;
    // Creates the Dropdown options based off the array above
    foreach($name_array as $k){
        echo "<option value=\"$k\">$k</option>\n"; }
    // Ends the Dropdown
    echo "</select>\n";
}
?>

<html>
<head><title>UG Pipeline Fiedl Data Capture</title>
</head>
<body>
<p></p>
<form action="<?php echo $PHP_SELF; ?>" 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:<?php dropdown('pipeno', 1); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 1); ?><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">
</td></tr></table></form> 

<p>
<form action="fieldbend.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="#ff9d9d">
<h3>Input Field Bend Information</h3>
Select Pipe No:<?php dropdown('pipeno', 2); ?>  Select Wall Thickness:<?php dropdown('wallthickness', 2); ?><br /><br />
Input Measured Distance: <input type="text" name="measureddistance">  Input Bend Angle: <input type="text" name="benddegree"><br><br>
Input Bend Type: <input type="text" name="bendtype"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>

<p>
<form action="apptally.php" method="post">
<table width="600" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#66CC66">
<h3>Input App. Tally Information</h3>
 Input Type: <input type="text" name="type">   Input Serial No: <input type="text" name="serialno"><br><br>
Input Reference ID: <input type="text" name="referenceid"><br><br>
<input type="Submit" name="submit" value="Submit">
</td></tr></table>
</form></P>

</body>
</html>

Here is my sample fieldtally table -

<code>fieldtally</code> table

Here is what the forms look like - html forms

note: I used select size="3" to show multiple lines for this image, but left it as standard 1 row in the code above.

share|improve this answer
    
I tried this but Im getting this errors - Notice: Undefined index: pipeno in C:\Users\iegbulefu\Documents\My Web Sites\Personal Site1\dropdown2.php on line 38. and it completely removes the wallthickness field from the form. which is this line - echo "<option value=\"".$row['pipeno']."\">".$row['pipeno']."</option>\n"; – Shade Oct 12 '12 at 13:19
    
Sorry, I have updated the code to fix the errors. Undefined index: pipeno is because you are using pg_fetch_row() so I should have used $row[0] instead of $row['pipeno']. The wallthickness field did not show because I left out the closing ?> tag before the </select> closing tag. Make these changes and let me know if it fixes the errors. – Sean Oct 12 '12 at 18:48
    
Hi Sean, I have made the necessary modification but it is still behaving the same way. – Shade Oct 12 '12 at 19:10
    
Hi Sean, I have made the necessary modification but it is still behaving the same way. The Wall Thickness and the Pipeno fields are both supposed to be dropdown and on the same form, it should also be above the submit tab as the users is expected to scroll throgh the two fields, select the pipeno and corresponding wall thickness and then enter data into 'jointno','measured length', and the serialno and then press the submit tab for the data to be pushed into the database. when i moved the Wallthickness field to the place below the php closing tag, it displays outside the form. – Shade Oct 12 '12 at 19:18
    
You have more things you need to correct then. (1) you have</form> before <form> - <p></form></P><form action="fieldtally.php" method="post">, (2) 'Wall Thickness should be a dropdown', but you posted it as a text box - Select Wall Thickness: <input type="text" name="wallthickness">. (3) 'it should be above the submit tab', but you don't show a 'submit tab' in the form or the other fields ('jointno','measured length','serialno'), so I don't know how to help you move them. Also, I find it interesting that you are creating your dropdowns from your previously posted rows in fieldtally. – Sean Oct 13 '12 at 22:25

and its here:

Select Pipe No: <select name="education"> </select>  Select Wall Thickness: <input type="text" name="wallthickness"><br><br>

You are openning the tag select and closing in the same line, and after you are putting the elements. To solve that, correct this lines:

Change:

Select Pipe No: <select name="education"> </select>  Select Wall Thickness: <input type="text" name="wallthickness"><br><br>

to:

Select Wall Thickness: <input type="text" name="wallthickness"><br><br>
Select Pipe No: <select name="education"> 

and close select tag before close body like this:

</select>
</body>

Here you are putting the elements in the tag select. Try that

share|improve this answer
    
Hi Mauricio, Thanks for your suggestion,I tried it but it did not make much difference, and was not able to resolve the issue. – Shade Oct 11 '12 at 21:07

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.