Jump to content

adding foreach to database


xxreenaxx1

Recommended Posts

I am stuck on inserting the data into mysql via php.

 

Its a foreach method and I am just stuck

 

include '../Database/take_an_exam.php';
$intNum = 1;
$intnumber = 1;


while( $info = mysql_fetch_array( $sqll )){  
  echo "<input type='hidden' name=\"Que_ID\" value=\"{$info['Que_ID']}\" /> ";
  echo " $intNum, {$info['Que_Question']} <br />\n"; 
   $intNum++;

for ($i =1; $i < 5; $i++) {  

echo "<input type=\"checkbox\" name=\"choice[{$info['Que_ID']}.$i][]\" />{$info['Que_Choice'.$i]}<br />\n";  
  $intnumber++;
}
}
?>

<input type="submit" value="submit" name="submit">

 

This is my form that can output the Question and its choices.

 

I am echoing this on to the next page, the code is shown below

<?PHP
session_start();
$name= $_SESSION['username1'];
echo "User ID: $name <br/>";
$gender = $_POST["choice"];
$que_ID = $_POST["Que_ID"];

foreach ($gender as $key => $array) {  
if($array)
{  
$val=1;
}

///echo "Question ID and the choice ID:$key. Value is:.$val <br />\n";
$well = array(floor($key), substr(strstr($key, '.'), 1));
//$well = array(floor($key), $key - floor($key));
echo "Question ID: $well[0], ";
echo "Choice: $well[1]. value: $val<br/>";
}
//}break;
?>

 

Now, instead of echoing. I just want to add this to mysql.

 

The layout of my sql is Que_ID, Ans_Choice1, Ans_Choice2, Ans_Choice3, Ans_Choice4, Use_ID

 

When I echo my php my outcome is

 

User ID: 2

Question ID= 1 Choice 1

Question ID= 2 Choice 3

Question ID= 3 Choice 4

Question ID= 4 Choice 1

Link to comment
Share on other sites

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.