Page 1 of 1

[php] insert data from form

Posted: Thu Jun 05, 2008 6:32 am
by natomiast
How can I insert data from form to database if one of form field name is dynamic?
Form example:

Code: Select all

 
$q = mysql_query("SELECT id, uczen_id, imie, nazwisko FROM uczniowie WHERE klasa='$klasa' ORDER BY 'nazwisko'");
            <form method="POST" action="nauczyciel/klasa.php">
             <?php
               echo'<table border="0">';     //dane pobrane z bazy wy?wietlane sa za pomoc? tablei
                    while($row = mysql_fetch_assoc($q))
                    {
                    echo'<tr>';
                        echo'<td width="25px">';  echo $i.'. ';  echo'</td>';
                        echo '<td><input type="checkbox" name="'.$i.'"  /"></td>';
                        echo '<td width="325px" ><b>'.$row["nazwisko"].' '. $row["imie"].'</b></td>';
                        echo '<td><input type="text" name="'.$row["uczen_id"].'" style="width: 50px; right:100;"><BR /></td>';
                    //   echo '<input type="hidden" name="name" value="'.$row["uczen_id"].'">';
                        $uczenid[$j]=$row["uczen_id"];
                        $j++;
                        $i++;
                    echo'</tr>';
                    }
                echo'</table>';
                echo '<BR />';
             ?>
             <input type="submit" value="Dodaj oceny" name="dodaj_ocene" style="background-image: url(../obrazy/guzik.gif); font-weight:bold;" />
            </form>
 
I need insert to database name of the text field and value witch user put on it.

Re: [php] insert data from form

Posted: Thu Jun 05, 2008 7:51 am
by Frozenlight777
A few things I noticed:
1) Your from has no html tags or php tags associated with it which would cause it to bomb. You could use php tags to echo the form.
2) Where are the $i and $j variables coming from? If you are getting them from the query, you shouldn't have to incriment them in the loop. The loop should do it automatically.

I'll continue to look at it to fully understand the question.