我正在使用一个提交按钮来更新数据库中的数据并发送电子邮件。但是,数据并未保存到数据库中。代码如下所示:
<?php
if(isset($_POST['order_status']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$orderno =$_POST['order_no'][$i];
$status =$_POST['order_status'][$i];
print_r($_POST['order_no']);
$sql = 'UPDATE Orders SET status="' . $_POST['order_status'] . '" WHERE Orderno="' . $_POST['order_no'] . '"';
mysql_select_db('PurchaseOrders');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
?>
<?php
if(isset($_POST['order_selected']))
{
$keys = array_keys($_POST['order_selected']);
foreach($keys as $key)
{
$to = $_POST['order_requested_by'][$key];
$subject = "Order Form Approval";
$message = "Your purchase order number: " . " " . $_POST['order_no'][$key] ." ". "is" ." ". $_POST['order_status'][$key] ;
$headers = "From: noreply@somewhere.com";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{header( 'Location: http://localhost/test/../' ) ; }
else
{print "We encountered an error sending your mail"; }
}
}
?>
在我的表单中,输入字段如下所示:
echo '<td><input type="text" readonly=true name="order_supplier['.$i.']" value="' . $row['Supplier'] . '"/></td>';
echo '<td><input type="text" readonly=true name="order_total_price['.$i.']" value="' . $row['totalprice'] . '"/></td>';
echo '<td><input type="text" readonly=true name="order_requested_by['.$i.']" value="' . $row['requestedby'] . '"/></td>';
echo '<td>';
echo '<select name="order_status['.$i.']" id="id" onchange="showUser(this.value)" >';
echo '<option value = "Pending" name="order_status['.$i.']" class = "pending"' . ($row['status'] == 'Pending' ? ' selected=selected' : '') . '>Pending</option>';
echo '<option value = "Approved" name="order_status['.$i.']" class = "approved"' . ($row['status'] == 'Approved' ? ' selected=selected' : '') . '>Approved</option>';
echo '<option value = "Disapproved" name="order_status['.$i.']" class ="disapproved"' . ($row['status'] == 'Disapproved' ? ' selected=selected' : '') . '>Disapproved</option>';
echo '</select>';
我真的不知道为什么会这样。当我单击提交时,会出现一条消息,表明数据已成功输入数据库。但是没有输入数据。非常感谢