Jump to content

Page Reload


divyac
 Share

Recommended Posts

I am trying a site like http://quizpage.com/..i have all the questions and options in the database and displaying all the questions with choices using a select query.Also i have an additional field named "correct answer" and i check whether the selected option is equal to the correct answer..My problem now is after clicking any of the option,it displays "right" or "wrong" and is automatically moving to the next question which should not happen.only after clicking the continue button it should move to the next question and if the answer is right or wrong that particular option should be highlighted in green or red respectively..what i should do for this??pls guide me.my coding is as follows:

<?include "includes/connection.php";//if(isset($_POST['continue'])){$result=mysql_query("select mathID,Question, option1, option2, option3, option4, option5, correctanswer from math_table ORDER BY RAND() LIMIT 1");$resultset=mysql_fetch_array($result);//}$option=$_REQUEST['option'];//$id=$_REQUEST['id'];$result1=mysql_query("select correctanswer from math_table where mathID='$_GET[id]'");$resultset1=mysql_fetch_array($result1);echo $option;echo $resultset1['correctanswer'];$divcolor="blue";if($option==$resultset1['correctanswer']){	$divcolor="green";}else{	$divcolor="red";}?><!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><script type="application/javascript">function showcont(){document.getElementById('continue').style.display='block';}</script></head><body><form><? if($divcolor=="green") { ?><div style="border:solid; border-color:#66CC66; width:50%; margin-left:250px; margin-top:150px;border-width:25px;"> <? } ?><? if($divcolor=="red") { ?><div style="border:solid; border-color:#FF0000; width:50%; margin-left:250px; margin-top:150px;border-width:25px;"> <? } ?><? if($divcolor=="blue") { ?><div style="border:solid; border-color:#0033FF; width:50%; margin-left:250px; margin-top:150px;border-width:25px;"> <? } ?><div><? $count=1; ?>Question <? echo $count; ?></div><ol><b><? echo $resultset['Question']; ?></b><? if($resultset['option1']!='') { ?><div><li><a href="maths.php?option=<?= $resultset['option1'];?>&id=<?= $resultset['mathID']; ?>" onclick="showcont();"><? echo $resultset['option1']; ?></a></li><li><a href="maths.php?option=<?= $resultset['option2'];?>&id=<?= $resultset['mathID']; ?>" onclick="showcont();"><? echo $resultset['option2']; ?></a></li><li><a href="maths.php?option=<?= $resultset['option3'];?>&id=<?= $resultset['mathID']; ?>" onclick="showcont();"><? echo $resultset['option3']; ?></a></li><? if($resultset['option4']!='') {?><li><a href="maths.php?option=<?= $resultset['option4'];?>&id=<?= $resultset['mathID']; ?>" onclick="showcont();"><? echo $resultset['option4']; ?></a></li><? } ?><? if($resultset['option5']!='') {?><li><a href="maths.php?option=<?= $resultset['option5'];?>&id=<?= $resultset['mathID']; ?>" onclick="showcont();"><? echo $resultset['option5']; ?></a></li><? }?></div><? } else{ ?><input type="text" name="answer" id="answer"/><?}?></ol><br /></div><br /><div align="center"><? if($divcolor=="red" || $divcolor=="green") { ?><input type="submit" name="continue" value="Continue" id="continue" style="display:none;"/><? } ?>  <input type="submit" name="quit" value="Quit" id="quit"/></div>  </form></body></html>

Link to comment
Share on other sites

If what you have posted is the code you are using, then of course it moves to the next question. Your isset($_POST['continue']) test has been commented out. Or am I misunderstanding something?
ya.I tried isset($_POST['continue']) but if i use it,the very first question is not getting reloaded and i am getting a blank page..so i commented it.pls guide me in this issue...Also, i have replaced onclick="showcont();" as onclick="showcont();return false;" but at that moment,i am getting next question on clicking continue button and not the color change(red and green)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...