Page 1 of 1

Newbie -- parse error: unexpected $

Posted: Wed Oct 02, 2002 4:00 pm
by Sky
NOTE: I just started php two days ago, so don't blast me too far 8O

I've been at this webiste business for a year+, and have known html for about half that. Now i've started php, and i'm trying to convert my site to php, and add a (very) simple login script. I've modified it to store the &loggedink or logged in value in a session. It used to bring you to a page to change your info after you logged in, and i changed it to just show logged in as $username along with stesting and edit links. it worked fine, except coming back to index, then it could only display login, even though the session was still active. then I tried to change it, and i messed something up. now i get parse error, unexpected $ in /home/virtual/site5/fst/var/www/html/mr/login.php on line 148 (last line is 147) so poor little me is confuesd. I'm sorry i'm bugging you with this, but I can't figure it out :oops:

any help would be appreciated...

Code: Select all

<?


/*
SCRIPT TREE
>function def
>check session

>action=login

>action=edit

>action=change info

>all else



*/


	//Create loggedin function
	function loggedin($username)
	{
		echo "<h4>You are currently logged in as $username</h4>";
		echo "<a href='index.php?action=edit'>Edit info</a><br />";
		echo "<a href='stest.php'>Session test</a>";
	}

	//Create error_message function
	function error_message($message, $username, $password)
	{
		echo "<H3> $message;</H3>";
		echo "<form action='$PHP_SELF' method='post'>";
		echo "<P>Username: <input type='text' name='username' value='<?echo $username;?>' class='i' /> /><br />";
		echo "Password: <input type='password' name='password' value='<?echo $password;?>' class='i' /> /><br />";
		echo "<input type='submit' value='Login' src='login.png' /></p>";
		echo "</form>";
	}
	
	//If you're still logged in set $logink and display loggedin
	if($_SESSIONї'logink'] == "true")
	{
		$logink = "true";
		loggedin($username);
	}

/* Simple Signup/Login script
  Created on: Feburary 22, 2001
  Copyright© 123 Make Me! All Rights Reserved.
  To get this script, goto http://123-makeme.com
  
  This Software is free and can be modified and redistributed
  under the condition that the copyright and information above
  stays intact and with the script.*/

#User Variables
$datafile="/home/virtual/site5/fst/var/www/html/mr/data.txt";
#End User Variales
#If the call for the script is to log them in, DO IT!
if($action == "login"):
	#This makes sure all fields are filled out.
	if((!$username)or(!$password))
	{
		#If there is one missing, send them to the error.
		error_message("One or more required fields were left blank!", $username, $password);
	}
    #Open the datafile and login the user.
	$file=file($datafile);
	while(list(,$value)=each($file))
	{
		list($fname,$femail,$furl,$fuser,$fpass,$blank)=split( "\|", $value);

		if($username==$fuser and $password==$fpass or $_SESSIONї'logink'] == "true")
		{
			loggedin($username);

		$logink="true";
		$_SESSIONї'logink'] = "true";
		}
	}
	if($logink==""):
		error_message("Login failed, bad username/password<br /> OR you haven't logged in at all.", $username, $password);
	endif;


elseif($action=="edit"): 
	{
		echo "<FORM action='$PHP_SELF?action=change' method='post' /><br />";
		echo "<P>Name: <input type='text' name='name'  value='$fname' class='i' /><br />";
		echo "E-mail Address: <input type='text' name='email' value='$femail'  class='i' /><br />";
		echo "Website Address: <input type='text' name='url' value='$furl' class='i' /><br />";
		echo "Password: <input type='text' name='newpass' value='$fpass' class='i' /><br />";
		echo "Current Username: <input type='text' name='username' value='$username' class='i' /><br />";
		echo "Current Password: <input type='text' name='password' value='$password' class='i' /><br />";
		echo "<input type='submit' value='Change'><br />";
		echo "</p>";
		echo "</FORM>";
	}

elseif($action=="change info"):
		#This makes sure all fields are filled out.
		if((!$name)or(!$email)or(!$url)or(!$username)or(!$password))
		{
			#If there is one missing, send them to the error.
			error_message("One or more required fields were left blank! Please re- login.", $username, $password);
		}
	#Open the datafile and login the user.
	$file=file($datafile);
	while(list(,$value)=each($file))
	{
		list($fname,$femail,$furl,$fuser,$fpass)=split( "\|", $value);
		if($username==$fuser && $password==$fpass)
		{
			$oldword="$fname|$femail|$furl|$fuser|$fpass|";
			$newword="$name|$email|$url|$username|$newpass|";
			$fp = fopen($datafile, "r"); 
			$data = fread($fp, filesize($datafile)); 
			fclose($fp); 
			$newdata = str_replace($oldword, $newword, $data); 
			$fp = fopen($datafile,"w"); 
			fwrite($fp,$newdata) or die ("error writing");
			fclose($fp);
			$succ = "1";
			echo "Everything was changed successfully! <A HREF="$PHP_SELF?action=login&username=$username&password=$newpass">Edit Again</ A>";
		}
	}
	if(!$succ):
		error_message("Login failed, bad username/password", $username, $password);
	endif;
else:
	{
		If(!$_SESSIONї'logink'])
			{
				echo "<FORM action='$PHP_SELF;?action=login' method='post'>";
				echo "<P><b>Username: </b><input type='text' name='username' class='i' /><br />";
				echo "<b>Password: </b><input type='password' name='password' class='i' /><br />";
				echo "<input type='submit' src='login.png' alt='Login' /></p>";
				echo "<a href='signup.php'>New? Sign up!</a>";
				echo "</form><br />";
			}
		elseif($_SESSIONї'logink'] == "true")
			{
				echo "";
			}
	}
 ?>
this file is included in my index file which has the session_start(); in it. so if you have any ideas... :)

Posted: Wed Oct 02, 2002 4:28 pm
by volka
you forgot a closing endif; before ?>
it might be helpful if you'd use either {...} or : ... else: syntax, not both

Posted: Wed Oct 02, 2002 5:55 pm
by Sky
Ohk. thanks. and what do you mean? like only useing just
if()
{
stuff;
}
or just
if():
whee;
endif;

? :D 8O :?: :o :P :wink:

Posted: Wed Oct 02, 2002 6:24 pm
by thedunn
Amazing. I came here to ask just the same question. I've looked over it and can't find anything wrong.
(I hope I'm not supposed to start a new thread...)
Thanks :)
[edit 2 - darn it the link isn't working...have to insert it into message]

Code: Select all

<html>
<head>
<title>Travel Game</title>
</head>
<body>
<?php
// names: from eq first page, to eq second page and mode eq third page;
// pages: first page eq where from, second eq where to and third eq mode of trans;
echo "You are going from:";
echo $_POST &#1111;"from"];
echo "to:";
echo $_POST &#1111;"to"];
echo "And using a:";
echo $_POST &#1111;"mode"];
echo "to get there.";
?><br><?php
if (strstr($_POST &#1111;"to"], "America")) &#123;
	if (strstr($_POST &#1111;"from"], "UK")) &#123;
		echo "Welcome to The U.S. of A, Britisher! Why don't we go have some coffee?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Spain")) &#123;
		echo "Mi poco espanol...";
	&#125;
	if (strstr($_POST &#1111;"from"], "Mexico")) &#123;
		echo "We have some great Mexican resturants here...want to try one?";
		?><br><?php
		echo "No, I don't mean Taco Bell.";
	&#125;
	if (strstr($_POST &#1111;"from"], "SouthAfrica")) &#123;
		echo "Hi there! There are some nice guided tours around here...want to go with me?";
	&#125;
	if (strstr($_POST &#1111;"from"], "America")) &#123;
		echo "You can't go from America to America!";
		?><a href="./travel.php">Go back and try again!</a><?php
&#125;
if (strstr($_POST &#1111;"to"], "UK")) &#123;
	if (strstr($_POST &#1111;"from"], "America")) &#123;
		echo "Hello American. I hope you are doing well. Can I interest you in some tea?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Spain")) &#123;
		echo "Mi poco espanol...";
	&#125;
	if (strstr($_POST &#1111;"from"], "Mexico")) &#123;
		echo "We have some great Mexican resturants here...want to try one?";
		?><br><?php
		echo "No, I don't mean Taco Bell.";
	&#125;
	if (strstr($_POST &#1111;"from"], "SouthAfrica")) &#123;
		echo "Hi there! There are some nice guided tours around here...want to go with me?";
	&#125;
	if (strstr($_POST &#1111;"from"], "UK")) &#123;
		echo "You can't go from the United Kingdom to the United Kingdom!";
		?><a href="./travel.php">Go back and try again!</a><?php
&#125;
if (strstr($_POST &#1111;"to"], "Spain")) &#123;
	if (strstr($_POST &#1111;"from"], "America")) &#123;
		echo "Wanna buy a watch?";
	&#125;
	if (strstr($_POST &#1111;"from"], "UK")) &#123;
		echo "Hello sir. May I interest you in a tour of my castle?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Mexico")) &#123;
		echo "We have some great Mexican resturants here...want to try one?";
		?><br><?php
		echo "No, I don't mean Taco Bell.";
	&#125;
	if (strstr($_POST &#1111;"from"], "SouthAfrica")) &#123;
		echo "Hi there! There are some nice guided tours around here...want to go with me?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Spain")) &#123;
		echo "You can't go from Spain to Spain!";
		?><a href="./travel.php">Go back and try again!</a><?php
&#125;
if (strstr($_POST &#1111;"to"], "Mexico")) &#123;
	if (strstr($_POST &#1111;"from"], "America")) &#123;
		echo "Hi! Would you like to see the ancient ruins of my village?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Spain")) &#123;
		echo "Aaaaaaaaaagh!";
	&#125;
	if (strstr($_POST &#1111;"from"], "UK")) &#123;
		echo "Dude! Want to go to a hip resturant?";
	&#125;
	if (strstr($_POST &#1111;"from"], "SouthAfrica")) &#123;
		echo "Hi there! There are some nice guided tours around here...want to go with me?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Mexico")) &#123;
		echo "You can't go from Mexico to Mexico!";
		?><a href="./travel.php">Go back and try again!</a><?php
&#125;
if (strstr($_POST &#1111;"to"], "SouthAfrica")) &#123;
	if (strstr($_POST &#1111;"from"], "America")) &#123;
		echo "Hi! Can I interest you in....DUCK!!!! *arrow shoots* dinner? *holds up duck*";
	&#125;
	if (strstr($_POST &#1111;"from"], "Spain")) &#123;
		echo "Hi! Welcome to Cape of Good Hope! Would you like to see the sites?";
	&#125;
	if (strstr($_POST &#1111;"from"], "Mexico")) &#123;
		echo "Hello, sir. Can I interest you in a few of these....watchshes?";
	&#125;
	if (strstr($_POST &#1111;"from"], "UK")) &#123;
		echo "Right this way, sir. Your hotel room with 1000 pounds cash is over here.";
	&#125;
	if (strstr($_POST &#1111;"from"], "SouthAfrica")) &#123;
		echo "You can't go from South Africa to South Africa!";
		?><a href="travel.php">Go back and try again!</a><?php
	&#125;
&#125;
?>
</body>
</html>

Posted: Wed Oct 02, 2002 7:05 pm
by Sky
I don't know how to fix it but i know you don't have to jump php to br. just go echo "<br />";

PS if someone would answer it would be nice... :lol: :wink:

Posted: Wed Oct 02, 2002 8:35 pm
by Sky
OO i downloaded Zend's editor... AWESOME!! i got it working!!! yahooo!!! NOw. i want to log out... i mean they just have to close the browserbut i mean seriously i want logout function. would form=phpself?action=logout input=submit and then if logout set 2 vars to "". would that work? me testie. :lol: :D :o

Posted: Wed Oct 02, 2002 8:41 pm
by volka
thedunn: you forgot a closing } after each ?><a href="travel.php">Go back and try again!</a><?php .
I suggest a syntax-highlighting editor that marks corresponding pairs of (curly) brackets.

Sky: ?

Posted: Wed Oct 02, 2002 8:44 pm
by Sky
that would be http://www.zend.com 's. GET IT for 21 days folks! LoL :lol: :wink:

Sorry if i'm bothering you forum regulars with newb-actions, i just can't help being one once i a while :wink: being the admin can get boring... 8O

Posted: Wed Oct 02, 2002 8:55 pm
by thedunn
Duh...thanks :) I'll check out Zend's.
[added]
W00! Working. Thanks a lot :)

tip

Posted: Wed Oct 02, 2002 8:56 pm
by Baka2002
A sugested tip would be to add the braces before you code. like this

if(condidtion)
{
}

then put code in then stupid syntax errors will not happen

Posted: Wed Oct 02, 2002 9:01 pm
by Sky
Ya, but what if you are modifying a script? anyway, this is what i'm using to log out... and i don't know why it's not working.
if($action == "logout" and $_SESSION['logink'] == "true" and $logink == "true")
{
$logink = "";
$_SESSION['logink'] = "";

echo "<h3>Session cleared</h3>";
}


ZHIIING!!! G'nite. 8O ........... :lol:

Posted: Thu Oct 03, 2002 12:54 am
by Takuma
Which version of PHP are you using?

Posted: Thu Oct 03, 2002 7:14 am
by Sky
The host is running 4.2.2

And i realized it was working, just that i had to refresh to see the changes. OOooo i like php -- when i'm more thann 3/4 awake that is...... :lol:

Posted: Thu Oct 03, 2002 8:54 am
by phice
:roll: :wink: