Greetings,
I've read what I could find on this subject but still am not getting it.
I have a four-field MySQL database. Field1 is text, the other fields are numeric.
I have a form that pulls all the data from the database into text boxes.
I'd like to be able to edit any or all of fields2,3,and 4 on the form (field1 is the primary key) and use a submit button to make all the updates at once.
Questions:
Is the output of the form (below) in the correct format for updating to a MySQL database?
Do I need field1 in the array since I'm not editing it? For some reason I suspect I do.
How on earth do I build a loop (foreach? while? or either?) that integrates an
<?php mysql_query("UPDATE....." ?> query. I've tried but a bunch of different things but I either get parse errors (because I have no clue what I'm doing) or an unformated version of the array shown below (which I find odd?).
If somebody could point me in the right direction, I'd appreciate it.
#my form:
<?php
mysql_pconnect("localhost","user","password")
or die ("MySQL Connection Failure");
mysql_select_db("database")
or die ("Can't Connect to Database");
$result = mysql_query("SELECT field1, field2, field3, field4 from database")
or die ("Database Query Failed!");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
extract($row);
echo "<tr>
<td width=100 align=left>
<input type='text' name=field1[] maxlength='10 size='12' value='$field1'</td>\n
<td width=85 align=right>
<input type='text' name=field2[] maxlength='6' size='8' value='$field2'></td>\n
<td width=85 align=right>
<input type='text' name=field3[] maxlength='4' size='8' value='$field3'></td>\n
<td width=85 align=right>
<input type='text' name=field4[] maxlength='6' size='8' value='$field4'></td>\n
</tr>\n";
}
?>
#Which is outputing like this:
Array
(
[field1] => Array
(
[0] => text
[1] => text
[2] => text
[3] => text
)
[field2] => Array
(
[0] => numeric
[1] => numeric
[2] => numeric
[3] => numeric
)
[field3] => Array
(
[0] => numeric
[1] => numeric
[2] => numeric
[3] => numeric
)
[field4] => Array
(
[0] => numeric
[1] => numeric
[2] => numeric
[3] => numeric
)
)