unexpected T_VARIABLE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
MeHigh
Forum Newbie
Posts: 13
Joined: Mon Jun 30, 2003 9:31 am

unexpected T_VARIABLE

Post by MeHigh »

I have this code

Code: Select all

<?php
<?php 
$six=6
$arrayname=array("this is the element",5,$six);
echo $arrayname[0];
echo $arrayname[1];
echo $arrayname[2];
?>
?>
and I get this error:

Parse error: parse error, unexpected T_VARIABLE in c:\_server\websites\2.php on line 3

Thanx
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

$six=6 most have a trailing ;
$six=6;

Move to PHP - Normal
User avatar
MeHigh
Forum Newbie
Posts: 13
Joined: Mon Jun 30, 2003 9:31 am

Post by MeHigh »

thanx a lot.

I'm a begginer.Iguess you noticed :lol:
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Yes :), but everyone has to begin somewhere....
User avatar
MeHigh
Forum Newbie
Posts: 13
Joined: Mon Jun 30, 2003 9:31 am

Post by MeHigh »

One more thing:
I have this other code

Code: Select all

<?php
<?php 
$bakery = array(
"cherry" => "5.00",
"cola" => "7.66",
"vanilla" => "4.51",
);

echo "the price for a cherry flavour is $bakery['cherry'] <br>";
echo "the price for a cola flavour is $bakery['cola'] <br>";
echo "the price for a vanilla flavour is $bakery['vanilla'] <br>";

?>
?>
Well..the problem is that I don't get the values.
I only get:

the price for a cherry flavour is
the price for a cola flavour is
the price for a vanilla flavour is

Thanx
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You need to change the code so that instead of things like this:

Code: Select all

echo "the price for a cherry flavour is $bakery['cherry'] <br>";
you have

Code: Select all

echo "the price for a cherry flavour is {$bakery['cherry']}<br>";
or

Code: Select all

echo "the price for a cherry flavour is $bakery[cherry]<br>";
or

Code: Select all

echo 'the price for a cherry flavour is '.$bakery['cherry'].'<br>';
Mac
User avatar
MeHigh
Forum Newbie
Posts: 13
Joined: Mon Jun 30, 2003 9:31 am

Post by MeHigh »

Thanx guys.

One more question: in something like

Code: Select all

<?php
$text = "blblblbllblblblbllbl text text "
?>
how can I enter a simple break?(like <br> for html)
and

what do \n and \r actually do?

Thanx :)
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

<?php 
$text = "blblblbllblblblbllbl<br> text text <br>" 
?>
\n and \r are the equivalent of pushing the enter key when typing, your code will start on a new line when you view the HTML source code but it will have no affect on what the browser displays.

Just makes it easier to debug your html output.
Post Reply