mysql select parse error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

mysql select parse error

Post by fariquzeli »

anyone know why i would get a parse error on this line:

Code: Select all

$sql = "SELECT * FROM technicians WHERE username = '$username_login' AND password = '$password'";

i thought i had all of the syntax correct.
technicians is the db, username is the field, $username_login is the text field variable being checked along with the $password variable being checked with the mysql database.
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

What do you get when you echo $sq1 ?

Did you check the sticky post in the PHP forum about variables in 4.2?
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

We don't have php version 4.2 so that wouldn't be it.

can't echo out the $sql because the parse error happens on the line with the variable $sql and then it stops executing itself.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try

Code: Select all

$sql = "SELECT * FROM technicians WHERE username = ''$username_login'' AND password = ''$password''";
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Silly me, I was thinking it was an SQL error, but parse error = PHP. Yeah, I think the problem could lie with the quotes in quotes. Also try:

Code: Select all

$sql = "SELECT * FROM technicians WHERE username = '".$username_login'". AND password = '".$password."'";
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

i think you meant

Code: Select all

$sql = "SELECT * FROM technicians WHERE username = '".$username_login."' AND password = '".$password."'";
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

all of the above still give me the same parse error

do i maybe have a connection wrong, could it be a variable misspelled, what are other possible reasons for this error?
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Yeah, try to see if the variables are set by echoing them out before you try to put them together. If they don't echo, then you have a problem.

And good eye, hobgoblin. While typing it in, all those triple quotes look the same.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

i'm such a <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>

god when you read through your mysql_select_db it looks the same if you just glance at it when you don't have the "s" in it.

myql_select_db

and of course you gotta remember the ";" which i didn't, i'm such a tard.
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

forgot to say thanks to you guys as well

you guys need to be sexed by many bisexual petite blonde haired girls with big boobs for your php smartness.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

And your original SQL statement was correct, you don't need to escape quotes or concatenate the variables.

hob_goblin and RandomEngy:

As long as the stuff was within double quotes (") it will be evaluated by PHP

$Work = "be";
print "This will $Work fine, as it is enclosed by double quotes 'Okay'";
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Heh, I guess I'm kind of paranoid about those things. Some part of me wants to keep the variables and the strings separate; it still seems weird to me to put variables inside of strings.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

I know what you mean, my main language was Delphi before I got into PHP. I think being able to put variables into strings is a godsend.

And,

$sql = "SELECT * FROM technicians WHERE username = '$username_login' AND password = '$password'";

is a lot easier to read than

$sql = "SELECT * FROM technicians WHERE username = '".$username_login'". AND password = '".$password."'";

and to spot where all the ' and the like are, as hob_goblin pointed out to you in this example :wink:
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Well, I think you're right. Maybe I will start doing that.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

dont get too sloppy.. pretty soon they will have to make a XPHP because of people like you :P
Post Reply