Forum Moderators: coopster

Message Too Old, No Replies

PHP if() does little tricks :/

         

Gero_Master

10:20 am on May 6, 2006 (gmt 0)

10+ Year Member



I have seen on some sites that they put a command inside IF() sentences, in my case:

if(mail(datadata)) {
echo "ok";
} else {
echo "not ok";
}

Problem is that in my case, it does still show the PHP errors when I turn off my mail server.

When mail server on:
it displays "ok" if mail is sent

Mail server off:
It can't send the mail; it shows PHP error and "not ok"

I need to get rid of the PHP error somehow...

eelixduppy

10:56 am on May 6, 2006 (gmt 0)



Hello...

Just change it so this to get rid of the echoing of the error:


if(mail(datadata)) {
echo "ok";
}

Then it should only echo "ok" when it works, and it will echo nothing when it doesn't

Hope this helps

eelix

KingMacro

2:48 pm on May 6, 2006 (gmt 0)

10+ Year Member



if you mean it comes up with the error from the mail function (ie. can not connect to server for example) then use @ to suppress errors

if(@mail(datadata)) {
echo "ok";
} else {
echo "not ok";
}

the @ will hide any error messages that the PHP script may generate, so you will only see the "ok" or "not ok" that your script is producing

Gero_Master

7:20 pm on May 6, 2006 (gmt 0)

10+ Year Member



ooh! So that's what it is ment for :)

Thanks!

I've seen those being used before, but I couldn't figure out what they were for. I thought it's just another type to write the comands :)

coopster

4:05 pm on May 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yep, that's PHP Error Control Operator [php.net] at work. You really shouldn't be displaying ANY errors on a production machine though. Send them to a log, but don't be displaying them.

eelixduppy

4:33 pm on May 8, 2006 (gmt 0)



You could also use error_reporting(0); to turn off all error reporting

eelix