|
Posted by Rik on 02/07/07 17:48
Auddog <will_k@hotmail.com> wrote:
> My form is created by querying my database for id, fname, lname of =
> employees
> and then I add an input box for hours worked. I want everyone that =
> works on
> the production lines listed. I then would like to be able to insert t=
he
> form information into a database. I just don't know how to do this. =
I'm
> grasping at straws right now.
>
> Here is my form code:
> <?php
>
> // see if any rows were returned
> if (mysqli_fetch_array($result) > 0) {
This would mean you always discard the first row, use =
mysqli_num_rows($result) instead.
> while (list($id, $fname, $lname) =3D mysqli_fetch_row($result)=
)
> {
> echo " <tr>
> <td><input name=3D$id-hours type=3Dtext size=3D4 maxlength=3D4 /=
>
> </tr>";
> }
> echo "</table>";
> }
I'd do this:
echo '<input name=3D"hours['.$id.']" type=3D"text" size=3D"4" maxlength=3D=
"4" >';
And upon receiving, you'll have an array in $_POST (or $_GET, but don't =
do =
that) named 'hours' containing the id as key and the value as the input.=
=
Check this with print_r($_POST['hours']);
To keep using the current form, you'd have to do something like this:
$hours =3D array();
foreach($_POST as $key =3D> $value){
if(preg_match('/^[0-9]+-hours$/i',$key){
$keyarray =3D explode('-',$key);
$hours[$keyarray[0]] =3D $value;
}
}
print_r($hours);
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|