Jump to content

Suppressing Errors with @


chester600

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/32087-suppressing-errors-with/
Share on other sites

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 author=onlyican link=topic=120176.msg492733#msg492733 date=1167332297]
You need to connect to the database first

Putting 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 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.
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 there
Check that you are connecting BEFORE you run the query

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.