Jump to content

Foreach Loop


verdrm

Recommended Posts

I need to insert POSTED values from radio buttons into MySQL.

 

The problem is that I dynamically generate the names of the radio buttons on my form page.

 

Ex:

 

$qid = 1 to start

 

<?php echo "<input name=\"$qid\" type=\"radio\" value=\"$response\" />" ?>

 

My code is this:

 

$qid starts at one but increases each loop

foreach($_POST[$qid] as $value)

{

mysql_query("INSERT INTO `results` (answer) VALUES (".$value."')");

}

 

Does anyone know how I can have DYNAMIC radio buttons with names 1,2,3, etc. and then insert them into the database?

 

On my INSERT page, I can successfully echo the selections of the radio buttons but it won't work that way in the foreach loop.

Link to comment
https://forums.phpfreaks.com/topic/97390-foreach-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.