<?php
$server="localhost";
$username="root";
$password="root";
$db_name="test";
$db=mysql_connect($server,$username,$password);
mysql_select_db($db_name,$db);
if(isset($_POST['btnsave']))
{
$quesid=$row['question_id'];
$question=$_POST['txtquestion'];
$ans=$_POST['choice'];
$mark=$_POST['mark'];
/*checking no of questions in question table
*/
$countcheck=mysql_query("select count (*) from question");
echo "no of questions in table are".$countcheck;
while($row = mysql_fetch_array($countcheck))
{
for(i=0;i<='$countcheck';i++)
echo $row[i];
}
$ab=mysql_query("SELECT * FROM question ");
while($row = mysql_fetch_array($ab))
{
$answr=trim($row['answers']);
echo $answr;
}
/*comparing values of strings*/
if(strcmp($ans,$answr)==0)
{
$mark=1;
}
else
{
$mark=0;
}
$a=mysql_query("INSERT INTO studans(studquest,answers,mark)
VALUES('$question','$ans','$mark')");
/*$a=mysql_query("INSERT INTO studans(studquest,answers)
VALUES('what is computer','electronic device')");*/
}
if(isset($_POST['btnnext']))
{
}
?>
<?php
$server="localhost";
$username="root";
$password="root";
$db_name="test";
$db=mysql_connect($server,$username,$password);
mysql_select_db($db_name,$db);
$results = mysql_query("SELECT * FROM question");
while($row = mysql_fetch_array($results))
{
$question=$row['questions'];
$choice1=$row['choice1'];
$choice2=$row['choice2'];
$choice3=$row['choice3'];
}
echo $row['questions'] ;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="frmstudquestn" method="post" action="stud_questnans1.php">
<input type="text" name="txtquestion" value="<?php echo $question; ?>" /><br />
<input type="checkbox" name="choice" value="1" /><?php echo $choice1; ?><br />
<input type="checkbox" name="choice" value="2" /><?php echo $choice2; ?><br />
<input type="checkbox" name="choice" value="3" /><?php echo $choice3; ?><br />
<input type="submit" name="btnsave" value="save" />
<input type="submit" name="btnnext" value="next" />
</form>
</body>
</html>