Jump to content

Recommended Posts

Hi there,

 

I have the following form something like the one below.

 

I am trying to figure out sql query that will insert the value of each select in the loop into a new row:

 

Any help would be greatly appreciated!

 

<form>

<?php do { ?>
<select name="name[]" id="name1">
<option value="">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="hidden" name="question" value ="<?php echo $row_questions['question_id']; ?>" />
<?php } while ($row_questions = mysql_fetch_assoc($questions)); ?>

<input type="hidden" name="user" value="Current user" />

<input type="submit" name="submit" id="submit" value="submit" />
</form>

 

Cheers!

Link to comment
https://forums.phpfreaks.com/topic/170375-inserting-multiple-rows-from-array/
Share on other sites

<form>

<?php while ($row_questions = mysql_fetch_assoc($questions)) { ?>
<select name="name[<?php echo $row_questions['question_id']; ?>]">
<option value="">Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<?php } ?>

<input type="hidden" name="user" value="Current user" />

<input type="submit" name="submit" id="submit" value="submit" />
</form>

 

You can now access every question using $_POST['name'][$row_questions['question_id']] like:

 

$_POST['name'][1]

$_POST['name'][2]

$_POST['name'][3]

..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.