Jump to content

How to post checkbox data into a new table.


xxreenaxx1

Recommended Posts

Hey

 

I have checkbox and when the user tick one or more box these should be stored as 0 or 1 but since its while loop, I am not sure how to work that out.

 

So far I have

 

<html>

<?php
session_start();
include '../Database/connection.php';

$Value24 = mysql_real_escape_string(trim($_POST['myselect'])); 

$_SESSION['smodule'] = $Value24;

?>
<body>
<form action="Test_Completed.php" method="post">
<?php

$query = mysql_query("
   SELECT *
FROM Test 
WHERE Tes_ID = '{$_SESSION['smodule']}'


");

while( $query1 = mysql_fetch_array($query) ) {
     echo "Test Name:  {$query1['Tes_Name']}";
}  

?>
<br>
<?php
$query = mysql_query("
   SELECT *
FROM User
WHERE Use_ID = '{$_SESSION['ssubject']}'


");

while( $query1 = mysql_fetch_array($query) ) {
     echo "User Name:  {$query1['Use_Name']}";
} 
?>
<br>
<?PHP

include '../Database/take_an_exam.php';
$intNumber = 1;
while($info = mysql_fetch_array( $sql ))
{
echo "$intNumber, {$info['Que_Question']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> ";
echo "{$info['Que_Choice1']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> ";
echo "{$info['Que_Choice2']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> ";
echo "{$info['Que_Choice3']} <br />\n";
echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> ";
echo "{$info['Que_Choice4']} <br />\n";

$intNumber++; 
}


?>
<input type="submit" value="submit"/>
</body>

</html>

</body>

</html>

 

<?PHP

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("Examination", $con);

//Get & clean value from POST data

$choice1 = mysql_real_escape_string(trim($_POST['choice1']));
$choice2 = mysql_real_escape_string(trim($_POST['choice2']));
$choice3 = mysql_real_escape_string(trim($_POST['choice3']));
$choice4 = mysql_real_escape_string(trim($_POST['choice4'])); 
$user = mysql_real_escape_string(trim($_SESSION['username1'])); 


//Create and run INSERT query
$query = "INSERT INTO Answer (`Ans_Answer1`, `Ans_Answer2`, `Ans_Answer3`, `Ans_Answer4`, `Que_ID`, `Use_ID`) 
          VALUES ('{$choice1}', '{$choice2}', '{$choice3}', '{$choice4}', '{$query1}', '{$user}')";
$result = mysql_query($query) or die (mysql_error());

$_SESSION['Ans_ID'] = mysql_insert_id();


header("location:check.php");

?>

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.