LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Parse error: syntax error, unexpected T_VARIABLE in line 8 (https://www.linuxquestions.org/questions/programming-9/parse-error-syntax-error-unexpected-t_variable-in-line-8-a-926775/)

gsness 01-31-2012 04:02 PM

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!!!!!

kbp 01-31-2012 04:13 PM

Are you using a text editor that does syntax highlighting? ... any syntax errors should show up clearly then.

Cedrik 01-31-2012 04:18 PM

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 


Cedrik 01-31-2012 04:23 PM

Quote:

Originally Posted by kbp (Post 4589732)
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

sundialsvcs 01-31-2012 04:35 PM

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!!!" :banghead:

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.

gsness 01-31-2012 04:57 PM

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!

gsness 01-31-2012 07:42 PM

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.

gsness 01-31-2012 07:50 PM

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.

kbp 01-31-2012 07:53 PM

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']);



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