Jump to content

Recommended Posts

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.

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

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

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"

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
}
?>

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.

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.

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?

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?

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";
}
?>

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.

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.

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.