Page 1 of 2

mysql select parse error

Posted: Wed Jul 03, 2002 2:28 pm
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.

Posted: Wed Jul 03, 2002 2:33 pm
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?

Posted: Wed Jul 03, 2002 2:39 pm
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.

Posted: Wed Jul 03, 2002 2:42 pm
by hob_goblin
try

Code: Select all

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

Posted: Wed Jul 03, 2002 2:51 pm
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."'";

Posted: Wed Jul 03, 2002 2:55 pm
by hob_goblin
i think you meant

Code: Select all

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

Posted: Wed Jul 03, 2002 3:07 pm
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?

Posted: Wed Jul 03, 2002 3:11 pm
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.

Posted: Wed Jul 03, 2002 3:17 pm
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.

Posted: Wed Jul 03, 2002 3:17 pm
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.

Posted: Thu Jul 04, 2002 7:40 am
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'";

Posted: Fri Jul 05, 2002 10:08 am
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.

Posted: Fri Jul 05, 2002 2:22 pm
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:

Posted: Fri Jul 05, 2002 2:25 pm
by RandomEngy
Well, I think you're right. Maybe I will start doing that.

Posted: Fri Jul 05, 2002 2:30 pm
by hob_goblin
dont get too sloppy.. pretty soon they will have to make a XPHP because of people like you :P