Simple Login Script error

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
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Simple Login Script error

Post by anthony88guy »

I am trying to make a simple login script, but i am getting an error on line 16: Parse error: parse error, unexpected T_STRING
Last edited by anthony88guy on Thu May 12, 2005 6:12 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your query string isn't a string.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

I would need quotes? Likes this?
Last edited by anthony88guy on Thu May 12, 2005 6:12 pm, edited 1 time in total.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

anthony88guy wrote:I would need quotes? Likes this?

Code: Select all

$registered = mysql_query("SELECT * FROM users WHERE user = "$user" && pass = "$pass"") or die(mysql_error());
no now you have syntax errors. Try

Code: Select all

$registered = mysql_query("SELECT * FROM users WHERE user = '$user' && pass = '$pass'") or die(mysql_error());
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

ok, thanks i am a total noob. Why can't my way work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the first way isn't a string. The second, if you look at the highlighted version you posted, doesn't parse right.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Because without escaping your quote characters PHP sees this:

Code: Select all

"SELECT * FROM users WHERE user = "

$user

" && pass = "

$pass

""
And there's no concatenation, so PHP throws a parse error.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

ok, thxs
Post Reply