[thelist] Looping through an updte query in php

Howard Cheng howcheng at ix.netcom.com
Tue Jan 22 16:02:20 CST 2002


PHP has a handy feature where you can throw all of your form inputs into an 
array by adding '[]' to the end of the form input name, such as:

<input type="text" name="myinput[]" ...>

Then when you post the form, $myinput is an array, where $myinput[0] is the 
first field, $myinput[1] is second, and so on.

Or, if you don't like that, you can also use the variable $HTTP_POST_VARS 
which is an associative array of all your form inputs.

$sql_fields = "(";
$sql_values = ") VALUES (";
foreach ($HTTP_POST_VARS as $key=>$val) {
         $sql_fields .= "$key,";
         $sql_values .= "$val,";
}

Or something like that.

At 11:25 AM 1/22/2002 -1000, john corry wrote:
>http://216.157.37.183/edit_rates.php
>
>I have this form (generated by PHP from a MySQL DB) that allows a user to
>edit rates information for a number of vacation properties.
>
>For each record in my 'rates' table, there is one row in the form that
>contains 4 text inputs with the rates for that record.
>
>I need to write a script that will write each of the input field's contents
>to the DB. Obviously, I don't want to hard code the SQL to reflect each row
>(what happens when I add a property?) But I don't know how to get all the
>form inputs as an array and loop through them, constructing the proper SQL
>as I go <though I did just give myself a little hint...it will use an array
>loop>
>
>Any tips?

::::::::::::::::::::::
Howard Cheng
howcheng at ix.netcom.com
AIM: bennyphoebe
ICQ: 47319315





More information about the thelist mailing list