Newbie php script help!

They have: 47 posts

Joined: May 2005

Ok, I don't see what's wrong with this. Here's my code:

<?php
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
  <head>
<style type=\"text/css\">
body {background: #000000;
           color: #D2D200;}
</style>

  <link rel=\"shortcut icon\" href=\"favicon.ico\" >
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">


    <title>Blue lions - Fear the power</title>
   

&lt;script language=\"javascript\" type=\"text/javascript\"&gt;
<!--

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos==\"random\"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
TopPosition=(screen.height)
?Math.floor
(Math.random()*((screen.height-h)-75)):100;}
if(pos==\"center\"){LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!=\"center\" && pos!=\"random\") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,
directories=no,status=no,
menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
&lt;/script&gt;

  </head>
  <body>
    <td class=\"center\" valign=\"top\">
session_start();
echo \"Hello \".
$_SESSION['username'].\"<p>\"


echo \"Your user level is '.
$_SESSION['user_level'].' \" which enables
    you access to the following areas: <br />\";

if(
$_SESSION['user_level'] == 0){
    echo \"- Forums<br />- Chat Room<br />\";
}
if(
$_SESSION['user_level'] == 1){
    echo \"- Forums<br />- Chat Room<br />- Wall papers<br />\";
}
if(
$_SESSION['user_level'] >= 2){
    echo \"- Forums<br />- Chat Room<br />- Wall papers<br />- Members pages<br />\";
}


echo \"your password is \".
$_SESSION['password'].\" to change it click <a href=\\"changepass.php\\">here</a><br>\";
;




echo\"you have \".
$_SESSION['points'].\" points\";


echo \"<br /><a href=logout.php>Logout</a>\";



</td>
  </body>
</html>
?>

anyway, I'm getting an error on line 36

<?php
echo \"Your user level is '. $_SESSION['user_level'].' \" which enables
    you access to the following areas: <br />\";
?>

I have no idea what's wrong, help!

By the way, I know that the html isn't perfect and that the page looks ugly, but I'm just testing something. Hope you can help!

This post is suitable for vegetarians

Busy's picture

He has: 6,151 posts

Joined: May 2001

change to:

echo "Your user level is ". $_SESSION['user_level']." which enables
you access to the following areas: ";

the problem was mis alignment of quotes, note you have 3 double quotes and are trying to escape the variable with single quotes when you have used double for the value.

You will also have a problem with this one:
echo "your password is ". $_SESSION['password']." to change it click here";
;
You have only escaped one of the double quotes in the tag, both need to be escaped (\"), so should look like so:
echo "your password is ". $_SESSION['password']." to change it click
here";

I take it you know there is no tags, just the and ones

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Just to add to Busy's response, you could also do the following:

echo "Your user level is {$_SESSION['user_level']} which enables
      you access to the following areas: <br />";
'

When you use double quotes for print or echo, you can include variables directly in the quotes. Becasue you are using an array, you surround it with the braces {}.

See: http://www.php.net/types.string for more information and examples. The section on variable parsing can be found at http://www.php.net/types.string#language.types.string.parsing

-Greg

They have: 47 posts

Joined: May 2005

Thanks so much for the help, I'm learning everyday Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.