我正在开发小型库存模型,并且在库存不足时尝试发送电子邮件

时间:2019-03-06 11:29:55

标签: pdo

我正在研究一个简单的pdo邮件功能。由于库存是列名,因此当库存少于10时,邮件应在pdo中自动发送。我不想使用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);

1 个答案:

答案 0 :(得分:0)

您只选择库存正好等于10的物品

WHERE as on stock = 10

也许这会帮助您:

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

另外,有关带空格的列名称,请参见以下内容:

How to select a column name with a space in MySQL