Файл: sa/trivia.php
Строк: 78
<?php
//welcome to php trivia
//this script can be downloaded from imafish.com
//if you need any help please email pete@imafish.com
//or come onto irc.netgamers.org #sulla and ask for pwhite
//you need to fill in the database information below
@mysql_connect( "localhost", "USERNAME", "PASSWORD" ) or die( "Couldn't connect to MySQL server." ); // CONNECT TO DB OR DIE
@mysql_select_db("DATABASE NAME") or die( "Couldn't connect to Database" );
//there shouldn't be any need to edit below this line unless you want to change the design
?>
<h1>PHP TRIVIA</h1>
<?php
if ($trivia_id == "")
{
$trivia_id = "1";
}
if ($answer)
{
$type = "1";
$sql2 = mysql_query("SELECT trivia_id, question, answer, alternative1, alternative2 from trivia where trivia_id = $trivia_id");
while($row = mysql_fetch_array($sql2)){
$answer2 = ($row["answer"]);
$alternative1 = ($row["alternative1"]);
$alternative2 = ($row["alternative2"]);
}
if ($answer == $answer2)
{
$correct = "1";
}
elseif ($answer == $alternative1)
{
$correct = "1";
}
elseif ($answer == $alternative2)
{
$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 trivia_id, question, answer, alternative1, alternative2 from trivia where trivia_id = $trivia_id");
while($row = mysql_fetch_array($sql3)){
echo ($row["answer"]);
echo "<br><br>";
}
}
}
else
{
$sql = mysql_query("SELECT trivia_id, question, answer, alternative1, alternative2 from trivia where trivia_id = $trivia_id");
while($row = mysql_fetch_array($sql)){
echo ("<b>Question</b><br><br>". $row['question'] ." ");
}
echo "<br><br><br><form name="trivia" method="post" action="$php_self">";
echo "<b>Answer</b><br><br><input type="text" name="answer" class="userinputnm"><br><input type="Submit" name="Submit" value="Submit" class="submitbuttonnm">";
echo "</form>";
}
if ($trivia_id == "1")
{
$trivia_id1 = "1";
$text = "";
}
else
{
$trivia_id1 = $trivia_id - "1";
$text = "Previous Question";
}
if ($trivia_id == "100")
{
$trivia_id2 = "2";
$text2 = "";
}
else
{
$trivia_id2 = $trivia_id + "1";
$text2 = "Next Question";
}
echo "<a href=trivia.php?trivia_id=$trivia_id1>$text</a>";
echo " ";
echo "<a href=trivia.php?trivia_id=$trivia_id2>$text2</a>";
echo "<br><br><a href=http://imafish.com/>ImAFish.com</a>";
?>