LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-31-2012, 04:02 PM   #1
gsness
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Parse error: syntax error, unexpected T_VARIABLE in line 8


Ok, firstly I am pretty new to PHP so I am really just learning. I have an user login page that seems to keep throwing me errors. Specifically:

Parse error: syntax error unexpected T_VARIABLE in line 8.

this is the snippet of code:

include_once 'srheader.php';
echo "<h3>User Log In</h3>";
$error = $user = $pass = "";

if (isset($_POST['user'])
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
{
$error = "Not all fields were entered<br />
}
else
{
$query = "SELECT user,pass FROM users
where user='$user' AND pass='$pass'";

if (mysql_num_rows(queryMysql($query)) == 0)
{
$error = "Username/Password Invalid<br />";
}
else
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
die ("You are now logged in. Please <a href='rnmembers.php?view=$user'>Click Here</a>.");
}
}
}
echo <<<_END

Line 8 is: $user = sanitizeString($_POST['user']);

I am stuck. Can anyone see what I did wrong?

Thanks!!!!!
 
Old 01-31-2012, 04:13 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Are you using a text editor that does syntax highlighting? ... any syntax errors should show up clearly then.
 
Old 01-31-2012, 04:18 PM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Please use php and /php markups, you are a web developper, no ?

PHP Code:
include_once 'srheader.php';
echo 
"<h3>User Log In</h3>";
$error $user $pass "";

if (isset(
$_POST['user'])
{
$user sanitizeString($_POST['user']);
$pass sanitizeString($_POST['pass']);
if (
$user == "" || $pass == "")
{
$error "Not all fields were entered<br />
}
else
{
$query = "
SELECT user,pass FROM users
where user
='$user' AND pass='$pass'";

if (mysql_num_rows(queryMysql($query)) == 0)
{
$error = "
Username/Password Invalid<br />";
}
else
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
die ("
You are now logged inPlease <a href='rnmembers.php?view=$user'>Click Here</a>.");
}
}
}
echo <<<_END 

Last edited by Cedrik; 01-31-2012 at 04:22 PM.
 
Old 01-31-2012, 04:23 PM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Quote:
Originally Posted by kbp View Post
Are you using a text editor that does syntax highlighting? ... any syntax errors should show up clearly then.
+1 even with the basic bbcode, the error seems obvious to detect
 
Old 01-31-2012, 04:35 PM   #5
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,378

Rep: Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108
Think like a parser ... which means, sometimes, "totally stupid."

If you are a parser, then you are in the business of trying to match-up some arbitrary bit of incoming text to some arbitrary grammar (which is a formal description of what "the language that you're supposed to be processing" is "supposed" to look like).

Now, every now and again, a syntax-error occurs, and when it does, "you fall down." But, simpleton that you are, you can only report the line-number where you actually fell, not where the original error occurred.

Quote:
if (isset($_POST['user']) <=============================== LQQKY HERE!
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
My eagle-eyes notice the missing right-parentheses in that if statement. This is probably where the chain-of-dominoes first began to fall, but it might not be the point at which the parser finally realized that it had landed in an unceremonious heap.

The moral of this story is thus: when any language compiler (or interpreter) seems to be telling you that "an error has occurred 'here,'" what it is actually saying is that the incontrovertible existence of an error has been discovered 'here.'" The actual point of failure is likely to be somewhere earlier, as in this case. All that you know for certain is that "it is nearby."

PHP uses state-of-the-art parser technology, and pretty much everyone else does, too. Therefore, "don't blame PHP," and, really, don't blame yourself either. They are all like this.

Quote:
Take hand, apply to forehead and repeat after me: "d'oh!!!"

Q: Why do computer programmers have flat foreheads?
P.S.: Indentation is your best friend. Use it, and use it consistently. If your editor has a "source code tidy" feature, use it. Parsers do not care about white space, but your human eye does.

Last edited by sundialsvcs; 01-31-2012 at 04:39 PM.
 
Old 01-31-2012, 04:57 PM   #6
gsness
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
DOH!

Thanks, I must have looked at that blasted thing for 20 minutes and never noticed the missing ). I cleared that up and am now throwing a could of other errors but think I will work through them before posting.

Thanks for your help!
 
Old 01-31-2012, 07:42 PM   #7
gsness
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Ok, new problem (sorry I am learning via trial by fire here). I fixed the parenthesis in my code and now am getting:
Parse error: syntax error, unexpected T_IS_EQUAL in index5.php on line 19

below is the nearby code:

if(isset($_POST['user']))
{
$user = sanitizeString($POST['user']);
$pass = sanitizeString($POST['pass']);
if ($user == "" | $pass == "")
{
$error = "Not all fields entered<br />";
}
else
{
$query = "SELECT user,pass FROM users
WHERE user='$user' and pass='$pass'";

if (mysql_num_rows(queryMysql($query))) == 0
{
$error = "Username/Password invalid<br />";
}
else
{
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
die("You are now logged in");
}
}
}
Line 19 is: if (mysql_num_rows(queryMysql($query))) == 0

I've done a few pages but this login page is killing me.

Last edited by gsness; 01-31-2012 at 07:48 PM. Reason: left out a bit of code.
 
Old 01-31-2012, 07:50 PM   #8
gsness
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
HAHAHAHAA I found it all by myself! I am sure I will end up posting again, but for now I will celebrate with a victory beer.
 
Old 01-31-2012, 07:53 PM   #9
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Have you not noticed the colour change in your editor? .. try this line for a start:
Code:
if (mysql_num_rows(queryMysql($query)) == 0
.. I count 3 open brackets and 2 close brackets - this is a problem

You also seem to have lost your underscores in:
Code:
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);

Last edited by kbp; 01-31-2012 at 07:55 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Bash: line 77: syntax error: unexpected end of file bribon Programming 8 07-13-2011 12:43 PM
Parse error: syntax error, unexpected '@' in php code minipro Programming 1 06-14-2011 04:33 AM
Parse error: syntax error, unexpected T_STRING in /home/dodonet2/public_html/includes bestbuddy Linux - Newbie 8 01-10-2010 08:31 PM
What is a Parse Error: syntax unexpected $end in Viewtopic_body.html.php sonia510 Programming 2 10-01-2009 04:43 PM
Parse error syntax error unexpected '{ ' on line chakaox Programming 2 04-29-2009 03:27 AM


All times are GMT -5. The time now is 09:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration