user2867893
user2867893

Reputation: 29

Adding a variable to PHP script causes another line to create an error

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

Upvotes: 0

Views: 58

Answers (5)

hexacyanide
hexacyanide

Reputation: 91759

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

Upvotes: 1

Funk Forty Niner
Funk Forty Niner

Reputation: 74220

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.

Upvotes: 2

user2092317
user2092317

Reputation: 3348

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

Upvotes: 0

basil.shine
basil.shine

Reputation: 21

write it like this just add ; at the end

$uname = "Name";

Upvotes: 0

Matt Clark
Matt Clark

Reputation: 28629

Missing a semicollen.

$uname = "name";

Upvotes: 0

Related Questions