我有问题。这是我的php& HTML:
<?php
if ($_POST['btn_tambah'] == 'tambah') {
$pathGambar = "gallery/" . $_FILES['gambar']['name'];
$SQL = "SELECT AUTO_INCREMENT as IDLapangan FROM information_schema.tables WHERE TABLE_SCHEMA = 'ta' AND TABLE_NAME = 'lapangan';";
$res = mysql_query($SQL, $link);
$row = mysql_fetch_object($res);
foreach ($pathGambar as $path => $value) {
$tambahGambar = mysql_query("INSERT INTO foto(path,id_portfolio) VALUES('" . $value . "',$row->IDPortfolio);");
}
?>
<HTML><BODY>
<div class="row">
<div class="form-group">
<div class="col-lg-3"><label>Gambar :</label></div>
<div class="col-lg-2">
<input type="file" name="gambar[]" class="form-control" required>
</div>
<div class="col-lg-1">
<a onclick="tambahGambarBaru()" class ="btn btn-info"> <i class="fa fa-plus"></i></a>
</div>
</div>
</div>
<div id="sembunyiGambar">
</div>
</BODY></HTML>
这是我的剧本:
function tambahGambarBaru() {
$('#sembunyiGambar').append(
'<div class="row" id="imgBaru">'
+ '<div class="form-group">'
+ '<div class="col-lg-3">'
+ '</div>'
+ '<div class="col-lg-4">'
+ ' <input id="filePic" accept="image/*" type="file" name="gambar[]" class="form-control" required>'
+ '</div>'
+ '<div class="col-lg-1">'
+ '<a class ="btn btn-warning" onclick="hapus()"> <i class="fa fa-trash"></i></a>'
+ '</div>'
+ '</div>'
+ '</div>'
)
}
function hapus() {
$('#imgBaru').remove();
}
这是我的照片:
所以场景是,当我点击&#34;加&#34;按钮,它将显示第二个文本文件输入。我想将它们插入数据库。但是当我尝试插入时,它显示错误
为foreach()提供的无效参数
要显示第二个文本文件输入,我在javascript中使用.append
。
答案 0 :(得分:0)
对不起这是我的错。 所以,它应该是这样的:
$pathGambar = $_FILES['gambar']['name'];
foreach ($pathGambar as $path => $value) {
$tambahGambar = mysql_query("INSERT INTO foto(path,id_portfolio) VALUES('" . $value . "',$row->IDPortfolio);");
}
非常感谢:)