0
我有形式显示图像和使用foreach输入,并希望得到它在表单提交的价值,所以我可以implode它并保存到数据库,但不知道我怎么能做到这一点。到目前为止,我在表单上提交的唯一值是最后一个字段的值。这里是我的代码显示形式:Implode在表单中提交所有输入值
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<div class="row">
<div class="col-md-12 col-xs-12">
<?php
# Prepare the SELECT Query
$productimage = explode ("|", $productimage);
foreach ($productimage as $imgfile) {
echo '<div class="form-group">
<div class="col-md-8 col-sm-8 col-xs-12">
<div class="product-img">
<img class="img-thumbnail" src="../content/uploads/' . $imgfile . '" width="120" height="120" />
<input class="form-control" type="text" name="imgtitle">
<input type="hidden" name="imgurl" value="' . $imgfile . '">
</div>
</div>
</div>';
}
?>
<div class="form-group">
<div class="col-md-12 col-sm-12 col-xs-12">
<button type="submit" class="btn btn-primary" name="btn-saveimg">Save</button>
</div>
</div>
</div>
</div>
</form>
在表单提交,我要使用此代码来获取POST值:
if (isset($_POST['btn-saveimg'])) {
$imgurlUpdate = $_POST['imgurl'];
$imgtitleUpdate = $_POST['imgtitle'];
$arr = array($imgurlUpdate,'#',$imgtitleUpdate);
print_r($arr);
}
上的print_r,唯一的结果我得到的是表单的最后一个值。
Array ([0] => image4.jpg [1] => # [2] => title4)
我试图用破灭实现这样的结果:
image1.jpg#title1|image2.jpg#title2|image3.jpg#title3|image4.jpg#title4
,我可以保存到数据库中,如果例如我有4个图像。任何想法?
你的print_r()输出? –
嘿@MuhammadUsman谢谢你的提问。我只是更新了我的问题,并添加print_r() – RaffyM
的输出print_r($ _ POST)的输出吗? –