zed420 Posted June 2, 2008 Share Posted June 2, 2008 Hi All I wonder if someone can help me out here . I'm trying to make a quiz in my website, so far so good till I'm inserting these records into my database some of them won't display, the question shows but Options will not display. INSERT INTO php_tb VALUES ('3','Choose the correct HTML tag for the largest heading','<h6>','<head>','<h1>','<h1>'); INSERT INTO php_tb VALUES ('4',' What is the correct HTML tag for inserting a line break?','<lb>','<break>','<br>','<br>'); INSERT INTO php_tb VALUES ('5',' What is the correct HTML for adding a background color?','<background>yellow</background> ','<body bgcolor="yellow">','<body color="yellow">','<body bgcolor="yellow">'); INSERT INTO php_tb VALUES ('6','Choose the correct HTML tag to make a text bold','<bld>','<bold>','<b>','<b>'); INSERT INTO php_tb VALUES ('7','Choose the correct HTML tag to make a text italic','<italic>','<i>','<ii>','<i>'); Thanks in advance Zed Quote Link to comment Share on other sites More sharing options...
fenway Posted June 2, 2008 Share Posted June 2, 2008 What's the error? Where are the column names? Quote Link to comment Share on other sites More sharing options...
zed420 Posted June 2, 2008 Author Share Posted June 2, 2008 Thanks for the reply fenway, I've managed to display the data by using "htmlspecialchar", now the problem is its not counting those questions that have html tags "< >"as an option. I hope I'm making sense. $Query="INSERT into $table (id,question,opt1,opt2,opt3,answer) values ('$id','$question', '$opt1' , '$opt2', '$opt3' , '$answer')"; Quote Link to comment Share on other sites More sharing options...
fenway Posted June 2, 2008 Share Posted June 2, 2008 What's not counting them? Quote Link to comment Share on other sites More sharing options...
zed420 Posted June 3, 2008 Author Share Posted June 3, 2008 The query wont count those questions that have tags as their options, for example Question Choose the correct HTML tag to make a text italic Opt1 <Italic> Opt2 <i> Opt3 <ii> When you click on Opt2 this should be counted as one of your right answer but it DOES NOT. but on same question if you don't use tags in options (Opt) it will work. This is how I am finding the results; $query = "SELECT * FROM php_tb ORDER BY id"; $result = mysql_query($query) or die ("Couldn't execute query 2."); if (!$_POST['submit']) { echo "<form method=post action=$PHP_SELF>"; while ($row = mysql_fetch_array($result)){ $id= $_POST["id"]; $question= $_POST["question"]; $opt1= $_POST["opt1"]; $opt2= $_POST["opt2"]; $opt3= $_POST["opt3"]; $answer= $_POST["answer"]; } } elseif ($_POST['submit']) { $score = 0; $total = mysql_num_rows($result); while ($row = mysql_fetch_array($result)){ $answer= htmlspecialchars($answer); $answer = $row[answer]; $z = "q$row[id]"; $z = trim($z); if ($_POST[$z] == $answer) { $score++; } } echo "<p align=center><b>You scored $score out of $total</b></p>"; echo "<p>"; if ($score == $total) { echo "Congratulations! You got all the question right!"; echo "<p>Well done $name, with a score of $score, </p>"; Quote Link to comment Share on other sites More sharing options...
fenway Posted June 3, 2008 Share Posted June 3, 2008 This must be a PHP issue.... Quote Link to comment Share on other sites More sharing options...
luca200 Posted June 4, 2008 Share Posted June 4, 2008 I find your code really hard to understand, anyway I'm pretty sure your problem is the way you treat data with htmlspecialchars(): if you store answers in db in plain html (as to say <b > - the space was left just for not bolding the text in my post! ) and then you use htmlspecialchars to give a value to your option field (as to say <b>), of course the user's selection won't match what you have in the db, because they are different strings... You'd better use some sort of an answer key (let's say a, b, or c) instead of its value. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.