form submit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
minds_gifts
Forum Commoner
Posts: 63
Joined: Mon Feb 10, 2003 4:23 am

form submit

Post by minds_gifts »

hello,
A question is displayed and if the user types the answer and submit it, it gives the information if the question is wright or wrong and provides the link to the next question.
Now, i made few modifications to the script and show three radio buttons and where the user can select the answer and submit it.Now, after i made changes it does'nt seems to be working.
Could somebody of you help me .

Thanks in advance

Code: Select all

<?php
include("contentdb.php");

?>

<?php

if ($id == "")
{
$id = "1";
}

if ($answer)
{
$type = "1";
$sql2 = mysql_query("SELECT * from quiz where id = $id");
while($row = mysql_fetch_array($sql2)){
$answer2 = ($row["answer"]);

}

if ($answer == $answer2) 
{
$correct = "1";
}

else
{
$wrong = "1";
}

if ($correct == "1")
{
$wrong = "0";
}
else
{
$correct = "0";
}

}

if( $type == "1" )
{
if ($correct == "1")
{
echo "<b>CORRECT</b><br><br>";
}

if ($wrong == "1")
{
echo "<b>WRONG</b><br><br> The correct answer was ";
$sql3 = mysql_query("SELECT * from quiz where id = $id");
while($row = mysql_fetch_array($sql3)){
echo ($row["answer"]);
echo "<br><br>";
}
}

}
else
{
$sql = mysql_query("SELECT * from quiz where id = $id");
while($row = mysql_fetch_array($sql)){
echo ("<b>Question</b><br>". $row['question'] ." ");
$opt1 = $row["opt1"];
$opt2 = $row["opt2"];
$opt3 = $row["opt3"];

}
echo "<br><br><br><form name="quiz" method="post" action="$php_self">";
echo "<input type="radio" name="q$id" value="$opt1">$opt1<br>";
echo "<input type="radio" name="q$id" value="$opt2">$opt2<br>";
echo "<input type="radio" name="q$id" value="$opt3">$opt3<br>";
echo "<input type="Submit" name="Submit" value="Submit">";
echo "</form>";
}

if ($id == "1")
{
$id1 = "1";
$radio = "";
}
else
{
$id1 = $id - "1";
$radio = "Previous Question";
}

if ($id == "100")
{
$id2 = "2";
$radio2 = "";
}
else
{
$id2 = $id + "1";
$radio2 = "Next Question";
}

echo "<a href=""quiz.php?id=$id1>$radio</a>";
echo "&nbsp; &nbsp; &nbsp; &nbsp;";
echo "<a href=""quiz.php?id=$id2>$radio2</a>";

?>
Post Reply