SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Test PHP Code

  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Test PHP Code

    Ok, I recieve the following Error message: Parse error: parse error in /usr/local/psa/home/vhosts/minnesotadelegation.com/httpdocs/plants/includes/runtest.inc on line 89

    Below is the code of runtest.inc. Everything works until you hit the for loop, and then line 89 is in there. I can't see any reason why this should not work. Even eliminating line 89 and the rest until the end of the for loop creates a parse error at any "print" command for the rest of the code! (Line 89 starts with "print"<table width=297 height=200>")

    <?
    function runtest()
    {
    include "includes/config.inc";
    global $stu_id;
    print"Test for $_COOKIE[lname], $_COOKIE[fname]</h1>";
    print"<p>Below is your test. You have no set time to complete it. <em><strong>Remember, you may not use any reference material during this test. </strong></em></p>
    <form name=\"test\" method=\"post\" action=\"\">";
    print"<input name=\"testtype\" type=\"hidden\" value=\"$_POST[testtype]\">";
    //EXECUTE ONCE PER PER TEST
    //CONNECT TO DATABASE
    sqlconnect($sqldatabasehost,$sqldatabaseuser,$sqldatabasepass,$sqldatabasename);
    $conn = mysql_connect("$sqldatabasehost", "$sqldatabaseuser", "$sqldatabasepass") or die(mysql_error());
    //ASSIGN TEST ID NUMBER
    $test_id = (rand()%100000);
    print "Test Identification Number: $test_id";
    print"<input type=hidden name=test_id value=$test_id>";
    //RETRIEVE QUESTION AMOUNTS SET BY HOUSE (PASSED VIA HIDDEN FIELDS from teststart.php)
    $passingscore = $_POST[passingscore]; //Overall passing percent
    $birdsquestions = $_POST[birdsquestions];
    $testlength = $_POST[testlength]; //Overall test questions
    $treesquestions = $_POST[treesquestions];
    $plantsquestions = $_POST[plantsquestions];
    $wildflowerquestions = $_POST[wildflowerquestions];
    $birdspass = $_POST[birdspass];
    $plantspass = $_POST[plantspass];
    $treespass = $_POST[treespass];
    $wildflowerspass= $_POST[wildflowerspass];
    //END EXECUTE ONCE PER TEST

    //Plants-->

    if ($_POST[testtype] == 2 || $_POST[plants] == 1)
    {
    print"<h1>Plants</h1>";

    //RETRIEVE ALL POSSIBLE ANSWERS AND FORM THEM INTO AN ARRAY NEEDS TESTING
    $sql = "SELECT * FROM plants";
    $result = mysql_query($sql,$conn) or die(mysql_error());
    global $count;
    $count = 0;
    while ($answers = mysql_fetch_array($result))
    {
    $count = $count+1;
    $answer[$count] = $answers['name'];
    print "$answer[$count]<br>";
    }
    //RETRIEVE TEST QUESTION INFORMATION
    for ($i=0;$i<$plantsquestions;$i++)
    {
    $question_number=$i+1;
    $sql = "SELECT * FROM plants WHERE id = rand()%$count;
    $result = mysql_query($sql,$conn) or die(mysql_error());
    //ASSIGN RESULTS VARIABLE
    $organismid = mysql_result($result, 0, 'id');
    $imagepath = mysql_result($result, 0, 'imagepath');
    $correct_name =mysql_result($result, 0, 'name');
    //RETREIVE 4 RANDOM QUESTION ANSWERS THAT ARE INCORRECT FROM ARRAY
    $wrong_1 = $correct_name;
    $wrong_2 = $correct_name;
    $wrong_3 = $correct_name;
    $wrong_4 = $correct_name;
    if ($wrong_1 == $correct_name)
    {
    $number = rand()%$count;
    $wrong_1 = $answer[$number];
    }
    if ($wrong_2 == $correct_name)
    {
    $number = rand()%$count;
    $wrong_2 = $answer[$number];
    }
    if ($wrong_3 == $correct_name)
    {
    $number = rand()%$count;
    $wrong_3 = $answer[$number];
    }
    if ($wrong_4 == $correct_name)
    {
    $number = rand()%$count;
    $wrong_4 = $answer[$number];
    }
    //RANDOMIZE QUESTION ANSWERS & ASSIGN ANSWER ID
    //CORRECT ANSWER LOCATION 1=A 2=B 3=C 4=D
    $correct = rand(4);
    //SEND CORRECT ANSWER ID QUESTION ID TO DATABASE ALONG WITH STUDENT ID TEST ID ORGANISM ID NEEDS CORRECT DATA NAMES TESTING
    $insert = mysql_query(INSERT INTO results(answerid,questionid,stuid,testid,organismid) VALUES ('$correct','$question_number','$stu_id','$test_id','$organismid'), $conn) or die(mysql_error());
    //PRINT QUESTION TABLE NEEDS TESTING
    print"<table width=297 height=200>
    <tr>
    <th width=287 height=150 scope=col><font size = 16>#$question_number</font><img src=\"$imagepath\"></th>
    </tr>
    <tr>
    if ($correct == 1)
    {
    $answertext = $correct_name;
    }
    else
    {
    $answertext = $wrong_1;
    }
    <td><input name=\"question_$question_number\" type=\"radio\" value=\"A\">$answertext</td>
    </tr>
    <tr>
    if ($correct == 2)
    {
    $answertext = $correct_name;
    }
    else
    {

    $answertext = $wrong_2;
    }
    <td><input name=\"question_$question_number\" type=\"radio\" value=\"B\">$answertext</td>
    </tr>
    <tr>
    if ($correct == 3)
    {
    $answertext = $correct_name;
    }
    else
    {
    $answertext = $wrong_3;
    }
    <td><input name=\"question_$question_number\" type=\"radio\" value=\"C\">$answertext</td>
    </tr>
    <tr>
    if ($correct == 4)
    {
    $answertext = $correct_name;
    }
    else
    {
    $answertext = $wrong_4;
    }
    <td><input name=\"question_$question_number\" type=\"radio\" value=\"D\">$answertext</td>
    </tr>
    </table>";
    }// for i
    }

    //Birds-->
    if ($_POST[testtype] == 2 || $_POST[birds] == 1)
    {
    print"<h1>Birds</h1>";
    print"<p>&lt;Test Item&gt; </p>";
    }

    //Trees-->
    if ($_POST[testtype] == 2 || $_POST[trees] == 1)
    {
    print"<h1>Trees/Shrubs</h1>";
    print"<p>&lt;Test Item&gt; </p>";
    }

    //Wildflowers-->
    if ($_POST[testtype] == 2 || $_POST[wildflowers] == 1)
    {
    print"<h1>Wildflowers</h1>";
    print"<p>&lt;Test Item&gt; </p>";
    }


    Print" <h1>Test Submission and Verification</h1>
    <p>You are now ready to submit this test for scoring.</p>";

    if ($_POST[testtype] == 2)
    {
    print"<p>
    <strong>By submitting this examination for scoring, you agree/acknowledge the following/strong></p>
    <p><strong>a) You did not use any kind of reference material during this exam (including other students)<br>
    b) You did not copy any other students examination question answers<br>
    c) You did not cheat on this examination in any way, shape, or form</strong></p>
    <p><em>Note: For this official exam, you will not see the questions that you got wrong, only your totals. </em></p>";
    }

    print"<p>";

    if ($stu_id == $_COOKIE[stuid])
    {
    print"
    <input type=\"submit\" name=\"Submit\" value=\"Submit For Scoring\">
    <input type=\"reset\" name=\"Reset\" value=\"Reset Exam Answers\">";
    }
    else
    {
    print "<br>You are not authorized to submit this form. Are you logged in? Has your session expired? (Sessions are only vaild for one hour)";
    }
    }
    ?>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi,
    Line 52: missing a closing " of the query
    $sql = "SELECT * FROM plants WHERE id = rand()%$count";

    BTW you might alsoneed single quotes around the $_POST array values ie: $_POST['tree']


    Cheers

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much!

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    No Problem pdhharris and welcome to the forums!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •