Welcome to WebmasterWorld Guest from 54.166.172.33

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

I just started learning PHP and i m getting an error.

     
3:44 pm on May 14, 2012 (gmt 0)

New User

5+ Year Member

joined:May 14, 2012
posts: 5
votes: 0


This error:
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/linktroo/public_html/maulin2good.c on line 8

here is a snippet of my report.php:
<html>
<body>
<?php
$image =$_POST['image'];
$cramit =$_POST['cramit'];
$movie =$_POST['movie'];
echo '[img]'.$image.'[/img]' ;
echo '[url='$cramit.']'.$movie.'720p BRRip[/url]' ;
?>
</body>
</html>


its obtaining the post data from a html form
4:13 pm on May 14, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 19, 2002
posts:3368
votes: 41


my guess, on line 8

'.$cramit
4:15 pm on May 14, 2012 (gmt 0)

New User

5+ Year Member

joined:May 13, 2012
posts:20
votes: 0


Hi
It is missing a "." on line 8.
Correctly:
echo '[url='. $cramit.']'.$movie.'720p BRRip[/url]';
4:36 pm on May 14, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
posts:14664
votes: 99


IMO it would be easier to use double quotes than single which in this case would be less confusing with fewer mistakes like those:

echo "[url=$cramit]$movie720p BRRip[/url]";
4:48 pm on May 14, 2012 (gmt 0)

New User

5+ Year Member

joined:May 14, 2012
posts: 5
votes: 0


Thanks worked fine now :D
4:59 pm on May 15, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Welcome aboard maulin2good. A little explanation behind some of those solutions.

When double quoted, " ", scalar variables will interpolate - that is, display their value. A scalar is a flat string value.

$this = 'that';

echo "The word is $this"; // echoes The word is that

Single quotes do NOT interpolate.

echo 'The word is $this'; // echoes The word is $this

Enter the dot, the concatenation operator, which is how you can paste together strings.

echo 'The word is ' . $this;

Given the previous, incrediBill is correct - you use one or the other in ways that simplify your programming.

Enter arrays: arrays are associative or list collections. They don't adhere to these rules. You can't do this.

echo "The word is $_POST['value]";

So you have to concatenate, or use curly brackets to disambiguate what you mean. The curly brackets are a multi-purpose operator in PHP, you probably already know about control blocks (if/else, while) and functions (function this_that() {} ), but not many know about or use them for {disambiguation}. Consider an array like $_POST or $_GET from forms, which is a key/value pair,

$_POST = array (
'image' => 'kate-winslet-when-she-was-hot.jpg',
'cramit' => 'tight space between a boat and an iceberg',
'movie' => 'The Titanic'
);

Curly brackets allow you to interpolate those array variables just like scalar variables when double quoted.

echo "The movie was {$_POST['movie']} about a {$_POST{'cramit']} and here's an image: <img src=\"{$_POST['image']}\" alt=\"{$_POST['movie']}\"/>";

This even works on multidimensional arrays, which are arrays of arrays:

echo "my name is {$group_members['first-group']['fname']}";

But when you get confused, you CAN always concatenate:

echo "The movie was " . $_POST['movie'] . " about a " . $_POST{'cramit'] . " and here's an image: <img src=\"" . $_POST['image'] . "\" alt=\"" . $_POST['movie'] . "\"/>";

Enter escaping. Note the backslashes in the previous example. When you want to print out quotes inside PHP quotes of the same kind, you need to escape them as shown. This is also why a lot of PHP commonly creates Very Bad XHTML (IMO) that doesn't validate under XHTML strict (but is still "legal"):

echo "<img src='$img' alt='The alt'/>";

To validate it, you'd have to do one of these:

echo "<img src=\"$img\" alt=\"The alt\"/>";

echo '<img src="' . $img . '" alt="The alt"/>';

Which you use is really dependent on what makes for the least debugging and code legibility.

One last bit - you're still learning, but in respect to security with PHP, never use raw input from post or get. That's a topic for another thread, but look into it now while you're still learning.