Forum Moderators: coopster

Message Too Old, No Replies

What is wrong with my game maker script?

What is wrong?

         

Jeffrosproto

12:32 am on Nov 15, 2006 (gmt 0)

10+ Year Member



I always get the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jeffro/public_html/gamemaker/index.php on line 100

Can someone help? Thanks!

[edited by: coopster at 3:50 pm (utc) on Nov. 16, 2006]
[edit reason] removed code dump [/edit]

eelixduppy

12:55 am on Nov 15, 2006 (gmt 0)



Welcome to WebmasterWorld, Jeffrosproto.

Can you please just give us just the 100th line in the code that is creating the error?

Excessive code dumps aren't favored at this forum because it makes it hard to read and it isn't necessary either. Read the Charter [webmasterworld.com] for more details on this. Also, refer to this thread [webmasterworld.com] regarding troubleshooting.

Thanks

eelixduppy

1:15 am on Nov 15, 2006 (gmt 0)



Actually, taking a quick look at the script, I've stumbled upon some errors:

Here's a simplified example of what you want to do. It seems that some of your logic isn't correct, as well as some of your syntax.

page.php


<?php
if(empty($_POST['answers'])) {
?>
<form action="index.php" method="post">
Type question 1 here:
<select name="answers[]">
<option value="0" selected>Choose an answer</option>
<option value="Answer one">Answer one</option>
<option value="Answer two">Answer two</option>
<option value="Answer three">Answer three</option>
</select><br/>
Type question 2 here:
<select name="answers[]">
<option value="0" selected>Choose an answer</option>
<option value="Answer one">Answer one</option>
<option value="Answer two">Answer two</option>
<option value="Answer three">Answer three</option>
</select>
<input type="submit" value="Grade!" />
</form>
<?php
exit();
}
//else, continue with the grading!
$correct_answers = array("Answer two","Answer three");
$their_answers = $_POST['answers'];
$num_questions = count($correct_answers);
$score = 0;
for($i = 0; $i < $num_questions; $i++) {
if($their_answers[$i] === $correct_answers[$i]) {
$score++;
echo 'Question '.($i+1).' correct!<br/>';
} else {
echo 'Question '.($i+1).' is incorrect :(<br/>';
}
}
echo 'You got '.($score/$num_questions*100).'% of the questions correct!';
?>

There we go. It seems nicer, now does it work? I didn't try it, but everything looks ok. Give it a go first, and then try to see how you can implement it into your site :)

I'll be happy to explain how it all works; just ask if you want an explanation.

Jeffrosproto

10:50 pm on Nov 15, 2006 (gmt 0)

10+ Year Member



ok, thanks for the advice. I will not post long lines of code from now on. However, the above script doesn't seem to do what i want it to do. The script I posted above will take the options, put them into a big variable, then post that variable to a php page. The script you gave me will just be the test itself.

eelixduppy

10:56 pm on Nov 15, 2006 (gmt 0)



I'm not exactly sure what you want, then. Can you maybe give me an outline of what you want to accomplish. I think you are making this harder for yourself than it has to be.

Jeffrosproto

11:03 pm on Nov 15, 2006 (gmt 0)

10+ Year Member



ok, what i want is a script that can take a form's imputs, like the questions and correct answers, then put that together with the quiz script, then output that to a file. I am working on a sql one right now, but in the mean time I would like to have this too.