我有以下表单,正在通过数据库中的自动建议填充
<table class="table table-striped" id="itemsTable">
<thead>
<tr>
<th></th>
<th>Item Code</th>
<th>Description</th>
<th>Qty</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr class="item-row">
<td></td>
<form id="itemsForm" action="services/processOrder.php" method="post">
<td><input type="text" name="itemCode[]" value="" class="input-medium" id="itemCode"
tabindex="1"/>
</td>
<td><input type="text" name="itemDesc[]" value="" class="input-large" id="itemDesc"
readonly="readonly"/></td>
<td><input type="text" name="itemQty[]" value="" class="input-mini" id="itemQty" tabindex="2"/>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span>
<input
name="itemPrice[]"
class=" input-small"
id="itemPrice"
type="text"></div>
</td>
<td>
<div class="input-prepend input-append"><span class="add-on">€</span><input
name="itemLineTotal[]" class=" input-small" id="itemLineTotal" type="text"
readonly="readonly"></div>
</td>
</tr>
</tbody>
</table>
这是自动建议的 php 查询:
<?php
require_once('db_connection.php');
$return_arr = array();
$param = $_GET["term"];
$query = "SELECT field_id_5, exp_weblog_titles.title, field_id_57
FROM exp_weblog_data, exp_weblog_titles
WHERE exp_weblog_titles.entry_id = exp_weblog_data.entry_id AND field_id_5
LIKE '%". $param ."%'
LIMIT 10";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
/* Retrieve and store in array the results of the query.*/
while ($row = $result->fetch_assoc()) {
$row_array['jItemCode'] = $row['field_id_5'];
$row_array['jItemDesc'] = $row['title'];
$row_array['jItemPrice'] = $row['field_id_57'];
//$row_array['jItemWholesale'] = $row['itemWholesale'];
//$row_array['jItemRetail'] = $row['itemRetail'];
// $row_array['jQtyOnHand'] = $row['qtyOnHand'];
array_push( $return_arr, $row_array );
}
$result->free_result();
$mysqli->close();
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
最后这是通过电子邮件发送表单的 php:
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: " . $_REQUEST['repName'] . ">\r\n";
$to = 'dominic.mcafee@pmcnttyyre.com';
$subject = "Web Contact Data";
$fields = array();
$fields{"itemCode[]"} = "Code";
$fields{"itemDesc[]"} = "Description";
$fields{"itemPrice[]"} = "Price";
$body = "We have received the following information:\n\n";
foreach($fields as $a => $b){
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: noreply@example.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
$send = mail($to, $subject, $body);
if($send){
header( "Location:index.php" );
} else {
print "We encountered an error sending your mail, please try again";
}
?>
我在电子邮件中收到的只是“我们收到了以下信息: 代码: 描述: 价格: ”
请有人帮帮我。我哪里错了。我知道我已经很接近了,问题出在引用表单中的数据数组的某个地方。
最佳答案
很难从代码中看出,但主要原因是 $_REQUEST[$a] 为空。因此,请尝试在提交表单后立即回显整个 $_REQUEST,以便更好地进行调试。
此外,我没有看到提交按钮和表单标记的结尾 - 这也可能是错误。
关于PHP 表单处理未发送正确的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20657349/