Fill DB with values form dynamic forms

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
knallbernd
Forum Commoner
Posts: 30
Joined: Mon Apr 23, 2007 4:39 am

Fill DB with values form dynamic forms

Post by knallbernd »

Hi!
I've already posted about 2 weeks ago for a problem concerning dynamic forms.
Now I have another problem.

I create a query for teacher. First you have to pick a coursename from a list.
Then you get the names from this course and a dynamic form with those names is created:

Code: Select all

while($row = mysql_fetch_array($ergebnis))
  {           
     $rname = $row[0];
     echo "$rname
  <table>
   <tr><td>Frage1</td>
   <td><input type=\"radio\" name=\"Frage1[{$rname}]\" value=\"1\"></td>
   <td><input type=\"radio\" name=\"Frage1[{$rname}]\" value=\"2\"></td>
   <td><input type=\"radio\" name=\"Frage1[{$rname}]\" value=\"3\"></td>
    </tr>
   
   <tr><td>Frage2</td>
   <td><input type=\"radio\" name=\"Frage2[{$rname}]\" value=\"1\"></td>
   <td><input type=\"radio\" name=\"Frage2[{$rname}]\" value=\"2\"></td>
   <td><input type=\"radio\" name=\"Frage2[{$rname}]\" value=\"3\"></td>
</table>
And now I like to write the results back in the DB:

Code: Select all

for ($i=0; $i<3; $i++ ) {   
$f = "Frage".$i;
$array[$f] = $_POST[$f];


foreach ($array[$f] as $key => $element) {
        echo "In '".$key."' steht '".$element."'<br />\n";

if ($i==1){
       
   $Lehrender = $key;
   $f = $element;   
    $query = "INSERT INTO bewertung (Lehrender) VALUES ('$key')";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
   
}
// select and INSERT???
}
}
 mysql_close();
The big problem is that I don't manage to get the values ($key) to the according names. The names are only created when $i==1 because I only need them once.
In the DB it should look like this:

Lehrender / Frage1 / Frage2 / Frage3
Name1 / 1 / 3 / 2
Name2 / 2 / 5 / 6
Name3 / 3 / 4 / 1

I hope that my problem is understandable, maybe somebody could help me with this...
knallbernd
Forum Commoner
Posts: 30
Joined: Mon Apr 23, 2007 4:39 am

Post by knallbernd »

It would be really great if somebody could tell me how to go on or that I am maybe complete wrong with this.
Because I really don't manage to solve this problem...
Post Reply