.josh Posted November 11, 2008 Share Posted November 11, 2008 Okay seriously, stop with the posting of syntax errors. Syntax errors are like spelling errors. The error tells you exactly what to do. There's no reason why you shouldn't be able to figure that out. Especially if you use an editor that has code highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687316 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 With if (isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] == $username && $_POST['password'] == $password)){ what does "isset" mean/do? Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687321 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 isset is a function, that checks if the variable is set... that is if it has been assigned a value. (Click on a name to get to manual page on it) And in case you haven't yet here's tutorial on debugging PHP errors. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687323 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Are you serious, if it is in your code and you don't know what it does don't post it when you get errors. Google it, use the php manual. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687324 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 Are you serious, if it is in your code and you don't know what it does don't post it when you get errors. Google it, use the php manual. Once my school friend asked me to help him with a program ha was writing as a homework. I was surprised it was compiling at all as he obviously glued together parts of two other programs without really understanding what they're supposed to do, or even how to call them... That was fun.... sorta... Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687328 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 Sorry about not using code tags. quiz.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Geography Trainer Question Tool Panel</title> </head> <body> <table width="950" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="238" height="1"> </td> <td width="335"> </td> <td width="343"> </td> </tr> <tr> <td height="308"> </td> <td valign="top"> <?php $username = "dink87522"; $password = "dinky"; if (isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] == $username && $_POST['password'] == $password)){ //hidden <div align="center"><u><strong>Question Tool Panel</strong></u></div> ?> <br /> <strong>Category</strong> <select name="category"> <option>Africa</option> <option>Asia</option> <option>Europe</option> <option>North America</option> <option>Oceania</option> <option>South America</option> </select> <label>User <select name="user"> <option>Eddie</option> </select> <form id="form1" name="form1" method="post" action="process.php"> <label><strong>Question<br /> </strong> <textarea name="question" cols="50"></textarea> </label> <label><strong>Answer</strong><br /> <textarea name="answer" cols="50"></textarea> <br /> <br /> <input type="submit" name="Submit" value="Add question" /> (250 character limit for each text field) <br /> <br /> <div align="center">Copyright 2008 Geography Trainer</div> </form></td> <?php } else{ ?> <form method="POST" action=""><div align="center"> <table border="0"> <tr> <td>Username:</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password"></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Login"></td> </tr> </table> </div> </form> </table> </body> </html> I made the suggested changes and its still not parsing. "Parse error: syntax error, unexpected ')' in /www/oxyhost.com/d/i/n/dink87522/htdocs/quiz.php on line 20" Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687334 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 if (isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] == $username && $_POST['password'] == $password) Please read the errors and fix them yourself from now on. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687339 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 Thanks, but I still can't get it working. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687346 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 This is fixed, and the last time you must learn how to debug, and not post every error here. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Geography Trainer Question Tool Panel</title> </head> <body> <table width="950" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="238" height="1"> </td> <td width="335"> </td> <td width="343"> </td> </tr> <tr> <td height="308"> </td> <td valign="top"> <?php $username = "dink87522"; $password = "dinky"; if (isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] == $username && $_POST['password'] == $password) { //hidden ?> <div align="center"><u><strong>Question Tool Panel</strong></u></div> <br /> <strong>Category</strong> <select name="category"> <option>Africa</option> <option>Asia</option> <option>Europe</option> <option>North America</option> <option>Oceania</option> <option>South America</option> </select> <label>User <select name="user"> <option>Eddie</option> </select> <form id="form1" name="form1" method="post" action="process.php"> <label><strong>Question<br /> </strong> <textarea name="question" cols="50"></textarea> </label> <label><strong>Answer</strong><br /> <textarea name="answer" cols="50"></textarea> <br /> <br /> <input type="submit" name="Submit" value="Add question" /> (250 character limit for each text field) <br /> <br /> <div align="center">Copyright 2008 Geography Trainer</div> </form></td> <?php } else { ?> <form method="POST" action=""><div align="center"> <table border="0"> <tr> <td>Username:</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password"></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Login"></td> </tr> </table> </div> </form> </table> </body> </html> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687347 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 Thanks. Why at the bottom do you have <?php } ?> ? Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687445 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 To close the else{ statement. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687448 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 Oh I get it. With process.php I have <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Geography Trainer Question Tool Panel</title> </head> <body> <?php // Make a MySQL Connection mysql_connect("localhost", "dink87522_dink", "dinky") or die(mysql_error()); mysql_select_db("dink87522_db1") or die(mysql_error()); $q = "INSERT INTO moon (question, answer) VALUES('" . mysql_real_escape_string(stripslashes($_POST['question'])) . "', '" . mysql_real_escape_string(stripslashes($_POST['answer'])) . "')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); echo "Question successfully added ; ?> <br> <a href="quiz.php">Go Back to Question Tool Panel</a> </body> </html> <?php ?> and it gives the error Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /www/oxyhost.com/d/i/n/dink87522/htdocs/process.php on line 18 Can you please explain whats wrong with that lien of javascipt/my syntax. when I remove that lien of javascript that error goes away although then it gives an error about $end on line 21 for some unknown reason. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687453 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Try <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Geography Trainer Question Tool Panel</title> </head> <body> <?php // Make a MySQL Connection mysql_connect("localhost", "dink87522_dink", "dinky") or die(mysql_error()); mysql_select_db("dink87522_db1") or die(mysql_error()); $question = mysql_real_escape_string($_POST['question']); $question = stripslashes($question); $answer = stripslashes($_POST['answer']); $answer = mysql_real_escape_string($answer); $q = "INSERT INTO moon (question, answer) VALUES('$question','$answer')"; $rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); echo "Question successfully added"; ?> <br> <a href="quiz.php">Go Back to Question Tool Panel</a> </body> </html> I made it easier to read and fixed the error which was echo "Question successfully added"; You missed that closing tag, so it mucked up the rest of the script. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687454 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 Thankyou so much. its easy to understand when it is explained to you, but hard to find/do on your own. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687455 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 So a logical error here. After you add a question in takes you back to quiz.php and requires you to 'login' again. Is there a way, without using sessions which can work around this so that you don't have to sign in again after adding each question? Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687457 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Cookies, or Ajax Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687458 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 S for recalling the question: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Geography Trainer</title> </head> <body> <p>Geography Trainer</p> <p>Question: </p> <form id="form1" name="form1" method="post" action=""> <label>Your answer <input type="text" name="textfield" /> </label> <label> <input type="submit" name="Submit" value="Submit" /> </label> </form> <p> </p> </body> </html> and I am lost. How do I pull a question (randomly from the table column question) and then compare the user's entered answer to the question answer stored in the table? Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687511 Share on other sites More sharing options...
dink87522 Posted November 11, 2008 Author Share Posted November 11, 2008 Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687529 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Without knowing your database structure it is hard to say, but something like; <?php //connected already $sql = "SELECT * FROM table_questions ORDER BY RAND() LIMIT 0,1";//this way you will display one question from random from the database, you will need a way to check what questions they have answered. $sql = mysql_query($sql) or die ("Error!<br>".mysql_error()); $sql = mysql_fetch_assoc($sql); echo $sql['question'];//echo the question //user form, and user input $ans = $_POST['answer']; if($ans == $sql['answer']) { echo "correct answer"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687663 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 Note that in this case answer given will have to be worded exactly as the answer saved in database. So if the question was "President of which country is Barack Obama?", and the stored answer was "United States of America", but the user entered "USA", he would give an incorrect reply. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687670 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Yes, although i was under the impression it was dynamically created radio buttons, with the answer stored in the value. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687676 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 In such case, more than one possible answer for each question would have to be stored in database Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687678 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Yeah, that's the problem without knowing his database structure i have to guess a lot of it. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687681 Share on other sites More sharing options...
Mchl Posted November 11, 2008 Share Posted November 11, 2008 The workaround, without complicated things a lot could be making questions like this: "The country which president is Barack Obama is: A: Angola, B: England, C: USA" and take A,B or C as an answer. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687699 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Yeah, that could be a way, but i believe he maybe under the impression that it will be a simple task, when it will be fairly complicated, especially to someone who doesn't have a decent knowledge of mysql statements and php - mysql interaction. Quote Link to comment https://forums.phpfreaks.com/topic/132010-phpmysql-quiz-help/page/2/#findComment-687702 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.