Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 11-30-2004, 01:15 AM SQL syntax error
Sin
Junior Talker

Posts: 3
Trades: 0
This error has been bugging me for the past several days. What I want to do is create a register script that varifies that the user inputted fields are original and then submits it to the database and sends an email with the information.
Quote:
Invalid query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' password = 'test', alias = 'travisbickle', email =''' at line
Here's that line:
$result = mysql_query("SELECT * FROM game_users WHERE username ='".$username."', password = '".$password."', alias = '".$alias."', email ='".$email."'");
if(!$result) {
die('Invalid query: ' . mysql_error());

That error has stumped me and a few of my friends. Any help would be greatly appreciated!
Sin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-30-2004, 02:19 AM
foobar's Avatar
Extreme Talker

Posts: 225
Trades: 0
Try removing all the spaces around the equal (=) signs. That's the only thing I can see there ...
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-30-2004, 03:22 AM
Sin
Junior Talker

Posts: 3
Trades: 0
Invalid query: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'password= 'test',alias= 'travisbickle',email=''' at line 1

I get that when I remove the spaces between the equal sign.
Sin is offline
Reply With Quote
View Public Profile
 
Old 11-30-2004, 08:09 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
YOURS
SELECT * FROM game_users WHERE username ='".$username."', password = '".$password."', alias = '".$alias."', email ='".$email."'

Which will fail

MINE
SELECT * FROM game_users
WHERE username ='".$username."'
AND password = '".$password."'
AND alias = '".$alias."'
AND email ='".$email."'");

Spotted the difference?

Well in case not you queried on a couple of params but failed to do the right SQL to get it going. You used a comma seperated list when you need AND instead of , .

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 11-30-2004, 11:13 AM
foobar's Avatar
Extreme Talker

Posts: 225
Trades: 0
ibbo, you rule. I NEVER saw that. And I've been doing MySQL, Oracle and the good 'ol SQL queries for over 5 years ....
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-30-2004, 03:40 PM
Sin
Junior Talker

Posts: 3
Trades: 0
Yeah, it's working now. There's a parse error, but I can fix that. I'm not that great at SQL queries.
Foobar, no matter how much experience you have at something. You can still miss some of the simplist things (It's why newer players stomped all over me in Halo 2 ). It's no big deal though, atleast you tried to help.

Thanks again guys

Edit: I found out the parse error.

Your code:
SELECT * FROM game_users
WHERE username ='".$username."'
AND password = '".$password."'
AND alias = '".$alias."'
AND email ='".$email."'");

My new code:
mysql_query("SELECT * FROM game_users
WHERE username ='".$username."'
AND password = '".$password."'
AND alias = '".$alias."'
AND email ='".$email."'");

All I added was $result = mysql_query(". I believe I had to because it was down at the end of the script, but without it at the begining, the php engine wouldn't know how to read it. Well, something like that anyway. I know it's not the only way to fix this kind of error in this situation, but for me it was the easiest.
I just posted that because I mentioned the parse error and I for one think it's annoying when I try to help someone, but end up with a problem and they don't tell me what they did to fix it.

Last edited by Sin; 11-30-2004 at 04:03 PM..
Sin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to SQL syntax error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17159 seconds with 12 queries