Current location: Hot Scripts Forums » Other Discussions » Database » sql syntax error again


sql syntax error again

Reply
  #1 (permalink)  
Old 07-14-06, 02:16 PM
zitwep zitwep is offline
Wannabe Coder
 
Join Date: Aug 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy sql syntax error again

Ok, I know I am dumb for having so much problems with SQL queries, but could somebody let me know whats wrong with this now

PHP Code:

            $cookieuser $_COOKIE['' $companyname '_login_pass'];

            
$cookiepass $_COOKIE['' $companyname '_login_pass'];
            
$query "SELECT * FROM " $tblpref "members WHERE username = '" $cookieuser "';";
            
$getdata mysql_query($getdata) OR die(mysql_error());
            
$numrows mysql_num_rows($getdata); 
Giving me this error

Code:
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 'Resource id #41' at line 1
Thanks as usual for your help

zitwep
Reply With Quote
  #2 (permalink)  
Old 07-14-06, 02:20 PM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
You're running your mysql_query() on nothing.

Code:
$getdata = mysql_query($query) OR die(mysql_error());
Replace that line.


Cheers
Reply With Quote
  #3 (permalink)  
Old 07-14-06, 02:22 PM
zitwep zitwep is offline
Wannabe Coder
 
Join Date: Aug 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
oh **** I guess enough of the magic dragon for today

nah just joking, i guess im better stopping now getting tired.

thanks
zitwep
Reply With Quote
  #4 (permalink)  
Old 07-14-06, 03:24 PM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
Just my 2 cents: I see a lot of

Code:
SELECT * FROM ...
on this forum - I think its bad style. Make your intention mor obvious by stating the columns you need (this way you will also spot superflous columns, and you might reduce the memory foorprint of your scripts).

Just my thoughts on this.

Happy Coding!
__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
  #5 (permalink)  
Old 07-14-06, 03:26 PM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
And another tip:
Quite often, sql queries get built up dynamically. Therfore, I always log sql queries before executing them, its much easier to read them in a logfile than in the PHP Code
(often they are surrounded by a bunch of quotes - very hard to read!)

Cheers!
__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
  #6 (permalink)  
Old 07-14-06, 03:33 PM
Christian's Avatar
Christian Christian is offline
Community VIP
 
Join Date: Mar 2005
Location: ProgrammingTalk
Posts: 2,449
Thanks: 0
Thanked 6 Times in 5 Posts
Moved to Database.
__________________
:: ImperialBB :: New version in the works! :: http://www.imperialbb.com ::

:: Have a question about the board? The Rules? An Infraction/Warning? :: Contact Form ::
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't find error in sql syntax. Dr.Jamescook PHP 7 06-14-05 11:45 AM
You have an error in your SQL syntax. Help! SevEre PHP 7 09-08-04 05:05 AM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 10:22 AM
ERROR in SQL syntax near DATE_FORMAT() bitesize PHP 1 01-09-04 09:22 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 04:55 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.