Why is it not working?
Posted: Thu Jul 16, 2009 12:17 pm
// i have to display a question and 4 options . the user who has logged in can then answer.
// his answer is then compared with the right answer and then inserted in the table.
// after this when he relogs in we dont show the question again. but display a message
// but this code is giving me errors ...PLS HELP
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("168084",$con);
$result=mysql_query("SELECT * from tbl_twqmaster");
$row=mysql_fetch_array($result);
$result3=mysqli_query("SELECT * from tbl_twquser");
$row3=mysql_fetch_array($result3);
$displaya=0;
while($row3)
{
// to test if the user has already answered this weeks question
while($row)
{
if ($row3['twqId']==$row['id'])//also put same user condition
{
$displaya=1;
break;
}
else
$displaya=0;
}
}
if($displaya==0)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>This Weeks Question</title>
<meta name="" content="">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<form action="twq.php" method="post">
<?php
while($row)
{
echo $row['question'];
?>
<br>
<input type="radio" value="a" name="option"><?php { echo($row['opt1']); } ?></input> <br>
<input type="radio" value="b" name="option"><?php {echo($row['opt2']);} ?></input> <br>
<input type="radio" value="c" name="option"><?php {echo($row['opt3']);} ?></input> <br>
<input type="radio" value="d" name="option"><?php {echo($row['opt4']);}
}// end of while
?></input> <br>
<?php
mysql_close($con);
?>
<input type="submit" name="Submit">
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","168084","fecomps");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo("User Answer is :");
echo $_POST["option"];
mysql_select_db("168084", $con);
$option=$_POST["option"] ;
$result2=mysql_query("SELECT * from tbl_twqmaster");
while($row1 = mysql_fetch_array($result2))
{
if(strcmp($option,$row1['answer'])==0)
{
$ans=1;
echo "<br />";
echo "<br />";
echo "<br />";
echo "good... its a rite answer";
}
else $ans=0;}
mysql_query("INSERT INTO tbl_twquser (twqId,userId,answer)
VALUES (1,1,$ans)");
}//end of if displaya
else
{
echo("You have already answered this time question");
}
mysql_close($con);
?>
// his answer is then compared with the right answer and then inserted in the table.
// after this when he relogs in we dont show the question again. but display a message
// but this code is giving me errors ...PLS HELP
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("168084",$con);
$result=mysql_query("SELECT * from tbl_twqmaster");
$row=mysql_fetch_array($result);
$result3=mysqli_query("SELECT * from tbl_twquser");
$row3=mysql_fetch_array($result3);
$displaya=0;
while($row3)
{
// to test if the user has already answered this weeks question
while($row)
{
if ($row3['twqId']==$row['id'])//also put same user condition
{
$displaya=1;
break;
}
else
$displaya=0;
}
}
if($displaya==0)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>This Weeks Question</title>
<meta name="" content="">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
<form action="twq.php" method="post">
<?php
while($row)
{
echo $row['question'];
?>
<br>
<input type="radio" value="a" name="option"><?php { echo($row['opt1']); } ?></input> <br>
<input type="radio" value="b" name="option"><?php {echo($row['opt2']);} ?></input> <br>
<input type="radio" value="c" name="option"><?php {echo($row['opt3']);} ?></input> <br>
<input type="radio" value="d" name="option"><?php {echo($row['opt4']);}
}// end of while
?></input> <br>
<?php
mysql_close($con);
?>
<input type="submit" name="Submit">
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","168084","fecomps");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo("User Answer is :");
echo $_POST["option"];
mysql_select_db("168084", $con);
$option=$_POST["option"] ;
$result2=mysql_query("SELECT * from tbl_twqmaster");
while($row1 = mysql_fetch_array($result2))
{
if(strcmp($option,$row1['answer'])==0)
{
$ans=1;
echo "<br />";
echo "<br />";
echo "<br />";
echo "good... its a rite answer";
}
else $ans=0;}
mysql_query("INSERT INTO tbl_twquser (twqId,userId,answer)
VALUES (1,1,$ans)");
}//end of if displaya
else
{
echo("You have already answered this time question");
}
mysql_close($con);
?>