I have a problem. here is my 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>
here is my script:
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();
}
here is my pic:
So the scenario is, when i click the "plus" button, it will show up the second textfile input. I want to insert them into database. but when i try to insert, it shows error
invalid argument supplied for foreach()
To show up the second textfile input, i use .append
in javascript.