0

我正在尝试将数组数据插入数据库并且它正在工作,但问题是在向管理员发送包含有关插入数据的详细信息的邮件时。

我的代码:

if (isset($_POST['Submit']))
{
$var1 = $_POST['usr'];
$var2 = $_POST['category'];
$var3 = $_POST['prdname'];
$var4 = array_values(array_filter($_POST['prdid']));
$var5 = $_POST['price'];
$var6 = $_POST['qty'];
$var7 = $_POST['totals'];
}
$n = count($var4);

for ($i = 0; $i < $n; $i++)
{
$query = "INSERT INTO table (field1, field2, field3, field4, field5, field6, field7) 
VALUES ('$var1[$i]', '$var2[$i]', '$var3[$i]', '$var4[$i]', '$var5[$i]', '$var6[$i]', '$var7')"; 
$result = mysql_query($query) or die('Failed to connect to server: ' . mysql_error());
}

    foreach($var4 as $key => $v)
    {
    $v1 = $v['category'];
    $v2 = $v['prdid'];
    $v3 = $v['prdname'];
    $v4 =  $v['qty'];
    $v5 =  $v['price'];
$html = "
Specimen Copy Request Submitted By: <strong>$user</strong>
<p>Category       : $v1</p>
<p>Product Id     : $v2 </p>
<p>Products       : $v3 </p>
<p>Quantity       : v4 </p>
<p>Price      : $v5 </p>
";  
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);

$mail = $smtp->send($recipients, $headers, $body);
}
4

1 回答 1

0

像这样尝试这个块

foreach($var4 as $v)
    {
    $v1 = $v['category'];
    $v2 = $v['prdid'];
    $v3 = $v['prdname'];
    $v4 =  $v['qty'];
    $v5 =  $v['price'];
$html = "
Specimen Copy Request Submitted By: <strong>$user</strong>
<p>Category       : $v1</p>
<p>Product Id     : $v2 </p>
<p>Products       : $v3 </p>
<p>Quantity       : v4 </p>
<p>Price      : $v5 </p>
";  
于 2013-07-12T07:00:34.197 回答