Jump to content

jimmyo88

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Everything posted by jimmyo88

  1. Thanks for that, I looked in to the checked option so that all the options are set to true initially. I dont actually need to update the database with the answer. What i need the script to do is to add up all the correct answers and then give the total score. Whats giving me the problem is the switch statement. I can't seem to store the $_POST answer individually for each question. E.g. when i click submit, the code which shows me what values were posted <?phpecho "The answer submitted was ";echo $_POST['question'];?> the echo $_POST['question'] variable is the same for each question. So all questions are either true or false. Also because the submit button is part of the switch statement, this also gets echo'd out for each question. I've been looking at this same piece of code for about 6hrs now! I just want to move ahead with my project! thanks for taking the time with this.
  2. thanks a lot for the reply. Could you elaborate a bit more, I do not have $_POST['id'] in the script. I have a variable $dbid which contains the question number. Is this what i'm doing wrong? It's now 6am here, I think I may have to call it a night soon. I've been trying to get this working for about 10hours!!
  3. Hello everyone, I have a datatbase containing fields id, question, answer, and type. The questions are in true/false format, multiple choice and fill in the blank(text). At the moment, I am only trying to get the true and false questions to work. My code is as follows <?php $connection = mysql_connect("localhost","root","root") or die("couldn't connect"); $select = mysql_select_db("login") or die ("cannot select database!"); $query = mysql_query("SELECT * FROM questions"); $numrows = mysql_num_rows($query); if ($numrows!=0) { //code to login while($row = mysql_fetch_assoc($query)) { $dbquestion = $row['question']; $dbanswer = $row['answer']; $dbtype = $row['type']; $dbid = $row['id']; $correctanswer = explode('|',"$dbanswer"); switch($dbtype){ case "mchoice": echo"<br/>"; echo $dbquestion; echo"<br/>"; break; case "boolean": echo"<br/>"; echo $dbquestion; echo"<br/>"; echo $correctanswer[0]; //display radio buttons ?> <form name="boolean" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"> True <input name="question" type="radio" value= "True" /> False <input name="question" type="radio" value= "False" /> <input name="id" input type="hidden" value="<?php $dbid ?>" /> <input type="submit" name="submit" id="submit" value="Submit" /> <?php echo "The answer submitted was "; echo $_POST['question']; ?> <?php break; case "text": echo"<br/>"; echo $dbquestion; echo"<br/>"; //display text box break; } } } ?> The problem I'm having is that this creates a submit button for each question. When choosing true or false for the answer and pressing submit, the answer is selected for every question. I need the code to look at what the user has entered, check the answer against correctanswer[0]. I'm really in a bit of a hole here and if anyone can help me it would be greatly appreciated. Many thanks in advance James
×
×
  • 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.