gpt4 book ai didi

php - 在php中发布数组数据foreach循环

转载 作者:行者123 更新时间:2023-11-30 01:29:47 24 4
gpt4 key购买 nike

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

我的代码:

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);
}

最佳答案

像这样尝试这个 block

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>
";

关于php - 在php中发布数组数据foreach循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17609104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com