Jump to content

for each help?


Mr Chris

Recommended Posts

Hi all,

 

Wondering if you could help me with something.  I want to post two rows of data in one form, and it's working well:

 

<?php

if(isset($_POST['submit']))
{
$user_id = $_GET["user_id"]; 

foreach($_REQUEST['r'] as $the_answer)

  { 
      $result = mysql_query("Insert into cfm_survey (question_number,the_answer,user_id)   
                             values('$the_question','$the_answer','$user_id')");
  }

header("Location:survey.php?sec=3&user_id=1");

} //End of POST submit

?>
      <td style="width:100px;">Option 1</td>
  <INPUT TYPE="hidden" NAME="a[1]" VALUE="1" />
      <td style="width:80px;"><INPUT TYPE="radio" name="r[1]" value="Yes"></td>
      <td style="width:80px;"><INPUT TYPE="radio" name="r[1]" value="No"></td>
    </tr>
    <tr> 
      <td style="width:100px;">Option 2</td>
  <INPUT TYPE="hidden" NAME="a[2]" VALUE="1a" />
      <td style="width:80px;"><INPUT TYPE="radio" name="r[2]" value="Yes"></td>
      <td style="width:80px;"><INPUT TYPE="radio" name="r[2]" value="No"></td>
    </tr>
  </tbody>
</table>

 

...and you will see from the above code that the foreach code grabs the value for each of the $the_answer values and posts it accordingly.

 

However, you will also see a hidden value called 1 and 1a which I also want to post to the database as well in a variable named $the_question, in row one (value 1), and then in the second row (value 1a).

 

But I can't work out how to do it?  I tried to add an && operator to the for each and go from there, but php did not like it.

 

Any ideas?

 

Thanks

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/125460-for-each-help/
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.