htmlspecialchars issue
Posted: Wed Jun 04, 2008 4:44 pm
Hi All
I wonder if you can help me, I'm fairly new to PHP, I'm trying create a quiz for my website I did well so far till it came to insert html tags into databse. I've managed to insert and display them by using 'htmlspecialchar' but now the query wont count those questions that have tags as their options, for example
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;
Any help would be appreciated
Zed
I wonder if you can help me, I'm fairly new to PHP, I'm trying create a quiz for my website I did well so far till it came to insert html tags into databse. I've managed to insert and display them by using 'htmlspecialchar' but now the query wont count those questions that have tags as their options, for example
Code: Select all
Question Choose the correct HTML tag to make a text italic
Opt1 <Italic>
Opt2 <i>
Opt3 <ii>
Code: Select all
$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 = $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>";
Zed