[php] insert data from form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
natomiast
Forum Newbie
Posts: 5
Joined: Wed Jun 04, 2008 1:11 am

[php] insert data from form

Post 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.
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: [php] insert data from form

Post 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.
Post Reply