Jump to content

Recommended Posts

I am making a website to test people on their latin. I have a few words in a database, but I can't get the tester to work properly! It checks your answer against the database to see if its correct and states otherwise but does not move on to the next word. You can view it as it is at the moment here: www.teapay.com

 

Here's the code:

<? include('header.php'); ?>

<tr>
<td>
<div id="form"><form name="ad" action="index.php" method="POST">
<table width="50%" border="0px" cellspacing="0" cellpadding="5" align="center">
<p align="center"><font size="15px"><b>
    
<?   


if (isset($_POST))
{
$id = 1;
}
else
{
$id = $_POST['id']+1;
}



include('config.php');


    $sql = "SELECT * FROM tb_vb1 WHERE id='$id'";
          $result = mysql_query($sql);       
          $row = mysql_fetch_array($result);
            $lat = $row["lat"];
          mysql_close($con);
    echo "What is the English for $lat?";


    include('config.php');

          $sql = "SELECT * FROM tb_vb1 WHERE id='$id'";
          $result = mysql_query($sql);       
          $row = mysql_fetch_array($result);
          $eng = $row["eng"];
          mysql_close($con);
    if ($_POST['eng'] == $eng)

    {
    $alex = true;
echo 'Right!';
$id = $_POST['id']+1;

    }
    else
    {
    $alex = false;
echo 'Wrong!';
$id = $_POST['id'];
    } 

echo "$id";


?>



</b></font></p>
<tr>
<td width="100%" align="center" valign="bottom"><input type="text" name="eng" size="40" class="field"</td>
</tr>
<input type=hidden value="<? echo "$id"; ?>" name="id">
<tr>
<td width="100%" align="center" valign="bottom"><input type=submit value="Submit Your Answer" name="submit" class="form">
</td>
</tr>
</table>
</tr>
</td>
</table>
</form>
</body>
</html>

 

Thanks for your help!

 

I fixed it a bit...It now moves onto the next word but when it tests to see if you got it right, it tests it for the next word. SO to make it say "RIGHT" you have to type the answer to the next question in!

Here it is:

<? include('header.php'); ?>

<tr>
<td>
<div id="form"><form name="ad" action="index.php" method="POST">
<table width="50%" border="0px" cellspacing="0" cellpadding="5" align="center">
<p align="center"><font size="15px"><b>
    
<?   



if ($_POST['id'] == '')
{
$id = 1;
}
else
{
$id = $_POST['id']+1;
}

require('config.php');


    $sql = "SELECT * FROM tb_vb1 WHERE id='$id'";
          $result = mysql_query($sql);       
          $row = mysql_fetch_array($result);
            $lat = $row["lat"];
            $eng = $row["eng"];
          mysql_close($con);
    echo "What is the English for $lat?";


    if ($_POST['eng'] == $eng)
{
echo ' RIGHT!';
}
else
{
echo ' Wrong!';
}



?>



</b></font></p>
<tr>
<td width="100%" align="center" valign="bottom"><input type="text" name="eng" size="40" class="field" value="<? echo "$eng" ?>"></td>
</tr>
<input type=hidden value="<? echo "$id"; ?>" name="id" >
<tr>
<td width="100%" align="center" valign="bottom"><input type=submit value="Submit Your Answer" name="submit" class="form">
</td>
</tr>
</table>
</tr>
</td>
</table>
</form>
</body>
</html>

 

Thanks...

I re-structured it a little

 

<?php 
include('header.php'); 
include('config.php');

if (isset($_POST['id']))                                                           // if answer posted, check it
{
$id = $_POST['id'];
    $sql = "SELECT eng FROM tb_vb1 WHERE id='$id'";
$result = mysql_query($sql);       
$row = mysql_fetch_array($result);
$eng = $row["eng"];

    if ($_POST['eng'] == $eng)
    {
	echo '<p>Right!</p>';
    }
    else
    {
    	echo "<p>Wrong!, the English for \"{$_POST['lat']}\" is \"$eng\"</p>";
}
$id++;                                                                         // prepare for next question
}
else
{
$id = 1;                                                                       // just starting the test
}




$sql = "SELECT lat FROM tb_vb1 WHERE id='$id'";                                    // Now ask next question
      $result = mysql_query($sql);
             
      if ($row = mysql_fetch_array($result))
      {
      	$lat = $row["lat"];
  	echo "$id What is the English for \"$lat\"?";
      }
      else exit('Finished');

?>



<div id="form"><form name="ad" action="" method="POST">
<table width="50%" border="0px" cellspacing="0" cellpadding="5" align="center">
<p align="center"><font size="15px"><b>
    
</b></font></p>
<tr>
<td width="100%" align="center" valign="bottom"><input type="text" name="eng" size="40" class="field"</td>
</tr>
<input type=hidden value="<? echo "$id"; ?>" name="id">
<input type=hidden value="<? echo "$lat"; ?>" name="lat">
<tr>
<td width="100%" align="center" valign="bottom"><input type=submit value="Submit Your Answer" name="submit" class="form">
</td>
</tr>
</table>
</tr>
</td>
</table>
</form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.