-5

I am working on a simple pdo mail function. As on stock is column name, when stock is less than 10 then mail should go automatically in pdo. I don't wish to use SMTP.

include_once('database-config.php');
$email="abc@gmail.com";


$query = "SELECT slno, itemname FROM item WHERE as on stock = 10";

foreach ($dbh->query($query) as $row) {
    // Safe name for 70 char/line limit
    $itemname = (strlen($row['itemname']) > 40) ? (substr($row['itemname'], 0, 10) . '...') : $row['itemname'];
    // Prepare message data
    $subject = 'Out of stock - ' . $row['itemname'];
    $body = 'Product "' . $itemname . '" is out of stock.'  . "\r\n";
    $body .= 'Manage from http://localhost/oftest/login-system-in-php/guru-able/guru-able/default/adminhome.php?slno=' . $row['slno'] . "\r\n";

    mail($email, $subject, $body);
halfer
  • 19,824
  • 17
  • 99
  • 186
  • What is the question? – Dave Mar 06 '19 at 12:49
  • The `mail()` function is notoriously unreliable - use PHPMailer or SwiftMailer. However, if you need exact instructions about every line of code to write, you may not get the support you need here - it may be better for you to do some beginner tutorials first. – halfer Mar 06 '19 at 20:24
  • @Dave question is if stock is less in count the mail should go automatically – shreenidhi galagali Mar 07 '19 at 05:24

1 Answers1

0

you are only selecting items where the stock is exactly equal to 10

WHERE as on stock = 10

perhaps this will help you:

https://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html

also, see this regarding column names with spaces:

How to select a column name with a space in MySQL

imposterSyndrome
  • 896
  • 1
  • 7
  • 18