这是一个基本的php问题,而不是pdo问题,但是我得到的错误'Notice: Undefined index: body in /home/downlowd/www/dev/launch.php on line 20'
我试图在一些地方通过$_POST
,但只是让事情变得更糟。
<?php
require_once('config.php');
$attrs = array(PDO::ATTR_PERSISTENT => true);
$pdo = new PDO("mysql:host=localhost;dbname=".$dbname, $db_username, $db_password, $attrs);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$custlist = $pdo->prepare("SELECT * FROM customer_list");
$carrierlist = $pdo->prepare("SELECT * FROM carriers");
//$products = array();
$smsarrayobject = new ArrayObject($carrierlist);
if ($custlist->execute()) {
while ($row = $custlist->fetch(PDO::FETCH_ASSOC)) {
$prefix = $row['sms_num'];
if ($carrierlist->execute()) {
while ($rows = $carrierlist->fetch(PDO::FETCH_ASSOC)) {
$from = 'admin@telecomm.com';
$to = $prefix.$rows['carrieraddr'];
$body = $_POST['body'];
mail($to, $from, $body);
}
}
}
}
$pdo = null;
?>
<form action="" method="POST">
Your Message Body <input name="body" type="text" />
<input type="submit">
</form>
答案 0 :(得分:0)
你应该在执行代码之前检查$ _POST,这可以防止处理空输入,最好的方法是使用isset()函数检查:
if(isset($_POST['body']){
// your stuff
}