thecard Posted May 9, 2008 Share Posted May 9, 2008 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! Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/ Share on other sites More sharing options...
NorthWestSimulations Posted May 9, 2008 Share Posted May 9, 2008 Perhaps you could tell us what errors you are getting. Or what the problem seems to be Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537088 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 if (isset($_POST)) { $id = 1; } else { $id = $_POST['id']+1; } Fix that. =/ You never set the correct ID. At all. Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537089 Share on other sites More sharing options...
thecard Posted May 9, 2008 Author Share Posted May 9, 2008 The PROBLEM is that it never moves onto the next word in the database. It sets $id to the right value, but does not echo the appropriate row related to $id. Sorry DarkWater, what do you mean? Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537138 Share on other sites More sharing options...
DarkWater Posted May 9, 2008 Share Posted May 9, 2008 if (isset($_POST)) { $id = 1; } else { $id = $_POST['id']+1; } If $_POST is not set, you're trying to set $id = $_POST['id'] +1, which will yield 1....and so does the if statement. >_> Rewrite it so it actually works. Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537140 Share on other sites More sharing options...
thecard Posted May 9, 2008 Author Share Posted May 9, 2008 I'm trying to work it now, but am still confused! What should I write instead of if (isset($_POST))... ? Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537156 Share on other sites More sharing options...
DeanWhitehouse Posted May 9, 2008 Share Posted May 9, 2008 just a little thing i noticed this <input type="text" name="eng" size="40" class="field" not closed and you should change include to require ''; incase it can;t get one it won't continue then Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537159 Share on other sites More sharing options...
thecard Posted May 10, 2008 Author Share Posted May 10, 2008 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... Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537390 Share on other sites More sharing options...
Barand Posted May 10, 2008 Share Posted May 10, 2008 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> Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537409 Share on other sites More sharing options...
thecard Posted May 10, 2008 Author Share Posted May 10, 2008 You really are a genius lol. Nice one mate. Link to comment https://forums.phpfreaks.com/topic/104912-solved-php-latin-tester-program-please-help/#findComment-537761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.