PDA

View Full Version : sql syntax error again


zitwep
07-14-06, 03:16 PM
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


$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


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

landing
07-14-06, 03:20 PM
You're running your mysql_query() on nothing.


$getdata = mysql_query($query) OR die(mysql_error());


Replace that line.


Cheers

zitwep
07-14-06, 03:22 PM
oh **** I guess enough of the magic dragon for today :p

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

thanks
zitwep

duesi
07-14-06, 04:24 PM
Just my 2 cents: I see a lot of


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
07-14-06, 04:26 PM
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!

Christian
07-14-06, 04:33 PM
Moved to Database.