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:
Post
by fariquzeli » Wed Jul 03, 2002 2:28 pm
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.
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 2:33 pm
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 » Wed Jul 03, 2002 2:39 pm
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.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jul 03, 2002 2:42 pm
try
Code: Select all
$sql = "SELECT * FROM technicians WHERE username = ''$username_login'' AND password = ''$password''";
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 2:51 pm
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."'";
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Wed Jul 03, 2002 2:55 pm
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 » Wed Jul 03, 2002 3:07 pm
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?
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Wed Jul 03, 2002 3:11 pm
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 » Wed Jul 03, 2002 3:17 pm
i'm such a <span style='color:blue' title='I'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 » Wed Jul 03, 2002 3:17 pm
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.
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Thu Jul 04, 2002 7:40 am
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'";
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Fri Jul 05, 2002 10:08 am
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.
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Fri Jul 05, 2002 2:22 pm
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
RandomEngy
Forum Contributor
Posts: 173 Joined: Wed Jun 26, 2002 3:24 pm
Contact:
Post
by RandomEngy » Fri Jul 05, 2002 2:25 pm
Well, I think you're right. Maybe I will start doing that.
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Fri Jul 05, 2002 2:30 pm
dont get too sloppy.. pretty soon they will have to make a XPHP because of people like you