0

Quick question... I'm using this code to communicate with my flash application:

<?php
// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") {
// Print the var to flash
print "var1=The user's name is Harry";

}

?>

Now this works fine but as soon as I add a variable:

<?php
// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") {
$uname = "Name"
// Print the var to flash
print "var1=The user's name is Harry";

}

?>

I get an error stating:

Parse error: syntax error, unexpected T_PRINT in /home/a4935911/public_html/usersOnline.php on line 7

Where line 7 is my print statement. Why is this happening??? Please can someone help. PHP is driving me crazy...

5 Answers 5

2

Missing semi-colon in $uname = "Name"

change it to $uname = "Name";

Rewrite:

<?php
// Only run this script if the sendRequest is from our flash application
if ($_POST['sendRequest'] == "parse") {
$uname = "Name";
// Print the var to flash
print "var1=The user's name is Harry";

}

?>

Added note: A semi-colon can be omitted if it's the last line of code with nothing else that will be executed/included thereafter.

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly. When in doubt about a PHP error, always look at the last statement before the line at which PHP say there is a problem…
1

PHP requires that you end lines with a semicolon unless it is the last line. This is because if the semicolon is omitted, it will be evaluated as the same expression as the next line. Change this:

$uname = "Name"

To this:

$uname = "Name";

8 Comments

I think it's obvious that I'm new to PHP. Why is this causing a problem with the print function though? I think that's what confused me the most.
I'm pretty sure it's because the two lines are being evaluated as one.
Oh, that makes sense. I think I'm a bit over my head with PHP. Trying to use it before learning it. Thanks for your help everyone :)
@user2867893 You're welcome. Added note (from my answer) A semi-colon can be omitted if it's the last line of code with nothing else that will be executed/included thereafter.
I'm not that interested in PHP at the moment but I just need a bit of it to setup a project I'm working on. You both seem really knowledgable about PHP so do you think either of you could just give me a private hand sorting out some issues I have (I imagine all simple like this) so I don't have to ask too many questions on the forum. Thoughts?
|
0

Missing a semicollen.

$uname = "name";

Comments

0

write it like this just add ; at the end

$uname = "Name";

Comments

0

You need to end each statement with a semicolon ;

This error most often means you forgot one of these

' ; ' " ) ( [ ]

Change

$uname = "Name"

with

$uname = "Name";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.