0

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?

Rich
  • 5,603
  • 9
  • 39
  • 61
seoppc
  • 2,766
  • 7
  • 44
  • 76
  • 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 Apr 04 '11 at 13:22

5 Answers5

3

Just the problem part:

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

Need to change like this.

$_POST['city'] . '/'.$product_id.'.');
fabrik
  • 14,094
  • 8
  • 55
  • 71
2

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?

David
  • 208,112
  • 36
  • 198
  • 279
1

you should use

Postman::MailAlert($_POST['email'],'Hello '.$_POST['name'].', Thanks for signing up.Your customer id is '.$_POST['city'].'/'.$product_id);
Gaurav
  • 28,447
  • 8
  • 50
  • 80
1

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

Poelinca Dorin
  • 9,577
  • 2
  • 39
  • 43
1

$_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