0
votes

I am using the following static method for sending mail alerts, but its throwing an error: warning:division by zero ...

Postman::MailAlert($_POST['email'],'Hello '.$_POST['name'].', Thanks for signing up.Your customer id is '.$_POST['city']/'/'.$product_id.'.');

I have solved this issue by putting @, but why is this issue raised, and what am I doing wrong?

5
PHP.net : Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why. So it doesn't solve issue, it makes that issue ignored.Wh1T3h4Ck5
@Wh1T3h4Ck5 thanks for suggestion.seoppc

5 Answers

3
votes

Just the problem part:

$_POST['city']/'/'.$product_id.'.');

Need to change like this.

$_POST['city'] . '/'.$product_id.'.');
2
votes

Near the end of that line of code:

[...]$_POST['city']/'/'[...]

Add some spaces to make it clear:

[...] $_POST['city'] / '/' [...]

You're trying to divide $_POST['city'] by '/'. If non-numeric strings ('/') are interpreted by PHP as having a numeric value of 0, then you're dividing by 0.

Maybe you meant to concatenate instead of divide?

1
votes

$_POST['city']/'/' should become $_POST['city'].'/', common mistake when you type fast

1
votes

you should use

Postman::MailAlert($_POST['email'],'Hello '.$_POST['name'].', Thanks for signing up.Your customer id is '.$_POST['city'].'/'.$product_id);
1
votes

$_POST['city']/ <--- what is this slash doing here? I believe it's redundant. ;)

And just a side note - do you sanitize user input? I see you are directly using the $_POST array variables - don't do it. Users might submit just about anything here, even some nasty strings, and it's your responsibility to make sure that these won't compromise your application.

P.S.: Adding @ is a bad practice, since it only suppresses the error messages (removing the symptoms) while not fixing the cause. http://php.net/manual/en/language.operators.errorcontrol.php