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
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
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.