chester600 Posted December 28, 2006 Share Posted December 28, 2006 I am having trouble with a bit of code I am writing and am hoping for some help.I am writing a script which recieves data from a MySQL DB.I have written my query like this:[code]$query = "SELECT * FROM users";[/code]Then to run the query I have written this:[code]$result = mysql_query($query);[/code]Now when I run this code I always get this message in my browser:[code]<b>Warning</b>: mysql_query(): Access denied for user 'nobody'@'localhost' (using password: NO) in <b>/home/dartscou/public_html/results/search_results.php</b> on line <b>46</b><br />[/code]However if I put @ before mysql_query the code runs fine.Is it secure to do this or is there something else I am doing wrong????Thanks in advance!!!James Quote Link to comment Share on other sites More sharing options...
onlyican Posted December 28, 2006 Share Posted December 28, 2006 You need to connect to the database firstPutting an @ there, meens, Dont Show Error, so its not working$db = mysql_connect("localhost","username","password");mysql_select_db("DB_Name", $db);Change the information to be correct with you. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted December 28, 2006 Share Posted December 28, 2006 A quote from an expert...:file() is a function, and the @ sign will prevent PHP from generating any warnins/errors!Ted Quote Link to comment Share on other sites More sharing options...
alpine Posted December 28, 2006 Share Posted December 28, 2006 The code doesn't run fine, you're just removing the error message it gives. The error is still there.In general you should be careful with what you are surpressing, you won't discover what is wrong.http://no2.php.net/manual/en/language.operators.errorcontrol.php Quote Link to comment Share on other sites More sharing options...
chester600 Posted December 28, 2006 Author Share Posted December 28, 2006 [quote author=onlyican link=topic=120176.msg492733#msg492733 date=1167332297]You need to connect to the database firstPutting an @ there, meens, Dont Show Error, so its not working$db = mysql_connect("localhost","username","password");mysql_select_db("DB_Name", $db);Change the information to be correct with you.[/quote]Sorry forgot to say I have done that. I also get it when using mysql_fetch_array and mysql_num_rows. It those cases it comes up telling me that they are not valid MySQL resources or something.Thanks. Quote Link to comment Share on other sites More sharing options...
chester600 Posted December 28, 2006 Author Share Posted December 28, 2006 [quote author=alpine link=topic=120176.msg492736#msg492736 date=1167332641]The code doesn't run fine, you're just removing the error message it gives. The error is still there.In general you should be careful with what you are surpressing, you won't discover what is wrong.http://no2.php.net/manual/en/language.operators.errorcontrol.php[/quote]When I say it runs fine I mean it runs as I wanted it to.....although I expect there are still errors, I just cant see them. Quote Link to comment Share on other sites More sharing options...
alpine Posted December 28, 2006 Share Posted December 28, 2006 Try: $result = mysql_query($query) or die(mysql_error());See what it tells you Quote Link to comment Share on other sites More sharing options...
onlyican Posted December 28, 2006 Share Posted December 28, 2006 Your error code is coming up<b>Warning</b>: mysql_query(): Access denied for user 'nobody'@'localhost' (using password: NO) in <b>/home/dartscou/public_html/results/search_results.php</b> on line <b>46</b><br />Saying That the details are not thereCheck that you are connecting BEFORE you run the query Quote Link to comment Share on other sites More sharing options...
matto Posted December 29, 2006 Share Posted December 29, 2006 You will get that error if the user attempting to connect to mysql is expected to have a password. Can you post your actual code (of course replace password with ****** or something) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.