Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic form,update,refresh help

Status
Not open for further replies.

Jamfool

IS-IT--Management
Apr 10, 2003
484
0
0
GB
Ok I have a form that dynamically produces itself based on a query. Which sets the initial field values to the values returned from the query.

<input name=&quot;var1&quot; type=&quot;text&quot; value=<? print $row[3]; ?> size=&quot;5&quot;>


I want to then pass these values to a update sql, which updates the db. Then I want to reset the form to reflect these changes.

I want this to be done all in the same page, so i need to use php_self?

(also does it make any difference if the inputs are 'hidden' type)


Code:
<?php 
   include_once(&quot;db.php&quot;); 
   include_once(&quot;property.php&quot;); 

   mysql_select_db($database_Jmx, $Jmx); 
             
   # make a query on required item 
    
   $query = &quot;SELECT * 
FROM s INNER JOIN u_s ON s.s_id =u_s.s_id;&quot;; 

   $query_result_handle = mysql_query ($query) 
   or die ('The item intially select statement has failed'); 
    
   # make sure there is data 
   $num_of_rows = mysql_num_rows ($query_result_handle) 
   or die (&quot;The query: '$query' did not return any data&quot;); 
       
   # use mysql_fetch_row to retrieve the results 
    
   for ($count = 1; $row = mysql_fetch_row ($query_result_handle); ++$count) 
   { 

   ?> 


   <form action=&quot;<?php echo $PHP_SELF ?>&quot;> 
      <table width=&quot;100%&quot; border=&quot;0&quot;> 
               <tr align=&quot;left&quot;> 
                     <td><div align=&quot;left&quot;>v1</div> 
                        </td> 
                        <td> <? print $row[1];?> 
                        <input name=&quot;v1&quot; type=&quot;hidden&quot; value=<? print $row[1];?>></td> 
                  </tr> 
                  <tr> 
                        <td align=&quot;center&quot;><div align=&quot;left&quot;>v2</div> 
                        </td> 
                        <td><? print $row[2] ?> 
                        </td> 
                  </tr> 
                  <tr> 
                        <td width=&quot;17%&quot; align=&quot;center&quot;><div align=&quot;left&quot;>v3</div> 
                        </td> 
                        <td width=&quot;27%&quot;><? print $row[7] ?> 
                        </td> 
                  </tr> 
                  <tr> 
                        <td align=&quot;center&quot;><div align=&quot;left&quot;>v4</div> 
                        </td> 
                        <td><? print $row[0]; ?> 
                        </td> 
                  </tr> 
                  <tr> 
                        <td align=&quot;center&quot;><div align=&quot;left&quot;>v5</div> 
                     </td> 
               <td><input name=&quot;v5&quot; type=&quot;text&quot; value=<? print $row[3]; ?> size=&quot;5&quot;> 
                        </td> 
                  </tr> 
                  <tr> 
                        <td align=&quot;center&quot;><div align=&quot;left&quot;>v6</div> 
                        </td> 
                        <td><input name=&quot;v6&quot; type=&quot;text&quot; value=<? print $row[4]; ?> size=&quot;5&quot;> 
                        </td> 
                  </tr> 
                  <tr> 
                      <td align=&quot;center&quot;><div align=&quot;left&quot;>v7</div> 
                        </td> 
                        <td><input name=&quot;v7&quot; type=&quot;text&quot; value=<? print $row[5]; ?> size=&quot;5&quot;> 
                        </td> 
                  </tr> 
                  <tr> 
                        <td align=&quot;center&quot;><div align=&quot;left&quot;></div> 
                        </td> 
                        <td> </td> 
                        </tr> 
      </table> 
                        <input type=&quot;submit&quot; value=&quot;submit&quot; name=&quot;submit&quot;> 
                        <input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;> 
   </form> 
<? 
} 
      /* Free resultset */                         
      mysql_free_result($query_result_handle); 
   ?>
 
In your form, set a hidden field to anything:


<td>
<input type=&quot;hidden&quot; name=&quot;formupdate&quot; value=&quot;form1&quot;>
</td>


As soon as you load the page, check the post vars to see if the var is set:

<?php
//first check to see if the form has been used
if (issset($_POST['formupdate'])) && ($_POST['formupdate']==&quot;form1&quot;)) {
//if so do your db update in here
}
else {
//display the form with the data in here
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top