[英]How to get an email with all the dynamic checkbox values in php
我是PHP的新手,已经看到了一些类似的查询,但是我的涉及2个数组,我不确定如何将它们彼此相邻。 有人可以帮忙吗? 非常感谢! 我搬出家并建立了一个网站来出售我的东西,我在表格上有一个选择项并提供金额部分。 我希望它们在电子邮件中彼此相邻出现。
您可以在这里查看我正在创建的网站: http : //www.stasale.com
我有以下代码:
<table border="1">
<tr>
<th>Image</th>
<th>Name</th>
<th>Condition</th>
<th>Description</th>
<th>Asking Price</th>
<th>Select Item</th>
<th>Offer Value</th>
</tr>
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM stasale ORDER BY date DESC";
$data = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($data)) {
if (is_file(GW_UPLOADPATH . $row['image']) && filesize(GW_UPLOADPATH . $row['image']) > 0) {
echo '<tr><td><img src="' . GW_UPLOADPATH . $row['image'] . '" alt="' . $row['image'] . '" width="100" height="100"/></td>
<td>' . $row['name'] . '</td>
<td>' . $row['condition'] . '</td>
<td>' . $row['description'] . '</td>
<td>' . $row['askingprice'] . '</td>
<td><form method="post" action="mail.php"><input type="checkbox" name="itemname[]" value="' . $row['id'] . '">Select</td>
<td>Offer: <input type="text" name="offer[]"></td></tr>';
}
else {
echo 'Invalid row';
}
} ?>
<tr><td colspan="3">Contact Name:</td><td colspan="4"><input type="text" name="coname" width="300" ></td></tr>
<tr><td colspan="3">Contact Number:</td><td colspan="4"><input type="text" name="conumber" width="300" ></td></tr>
<tr><td colspan="3">Contact Email:</td><td colspan="4"><input type="text" name="coemail" width="300" ></td></tr>
<tr><td colspan="3">Questions/Comments:</td><td colspan="4"><input type="text" name="comments" width="300" height="100"></td></tr>
<tr><td colspan="7" align="center"><input type="submit" value="Send Request" name="submit" style="width:500px"/></form></td></tr>
</table>
我似乎无法解决如何从itemname []或offer []中获取值以显示在我的mail.php页面中的感觉,这是完全错误的:
if (isset($_POST['submit'])) {
$name = $_POST['coname'];
$email = $_POST['coemail'];
$number = $_POST['conumber'];
$comments = $_POST['comments'];
foreach ($_POST['itemname'] as $itemname)
foreach ($_POST['offer'] as $offer)
{
}
$to = 'shinobuden@gmail.com';
$subject = 'STASALE order';
$msg = "$name, $email, $number, $comments \n" .
"I would like: $itemname" .
"$offer";
mail($to, $subject, $msg, 'From:' . $email);
$to = "$email";
$subject = 'I have received your request - Si';
$msg = 'Thank you for contacting me! I have received your request and will reply shortly! ~ Si x';
$from = 'shinobuden@gmail.com';
mail($to, $subject, $msg, 'From:' . $from);
echo '<p><strong>Thanks for your request. I will respond as soon as possible.</strong></p>';
}
?>
提前谢谢你的帮助!
您可以执行以下操作:
foreach ($_POST['offer'] as $key => $value) {
if ($value) {
$offer_arr[] = $value;
}
}
$str = '';
for ($i = 0; $i <= count($_POST['itemname']); $i++) {
if ($_POST['itemname'][$i]) {
$str .= 'Item: ' . $_POST['itemname'][$i] . ' Offer: ' . $offer_arr[$i] . ', ';
}
}
$str
包含彼此相邻的所有项目和要约。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.