i try to insert multiple row in my database, that image not save to folder and
i get this error
Blockquote ArrayArrayYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Chrysanthemum.jpg’), (‘Hydrangeas.jpg’)’, ‘(‘Chrysanthemum.jpg’), (‘Hydrangeas.j’ at line 1
this is my code :
$hopid = $_POST[photo_hop_id];
$title = $_POST['photo_name_id'];
if(!is_array($title)) {
$title = array();
}
$titleds = "('" . implode("'), ('", $title) . "')";
$tmp_file = $_FILES['ne_photo_image']['tmp_name'];
$file = $_FILES['ne_photo_image']['name'];
if(!is_array($tmp_file)) {
$tmp_file = array();
}
if(!is_array($file)) {
$file = array();
}
$sementara = "('" . implode("'), ('", $tmp_file) . "')";
$filed = "('" . implode("'), ('", $file) . "')";
$tmp_file1 = $_FILES['fe_photo_image']['tmp_name'];
$file1 = $_FILES['fe_photo_image']['name'];
if(!is_array($tmp_file1)) {
$tmp_file = array();
}
if(!is_array($file1)) {
$file = array();
}
$sementara1 = "('" . implode("'), ('", $tmp_file) . "')";
$filed1 = "('" . implode("'), ('", $file) . "')";
if(!move_uploaded_file($sementara, 'image/' . $filed)) {
echo $_FILES["ne_photo_image"]["error"];
}
if(!move_uploaded_file($sementara1, 'image/' . $filed1)) {
echo $_FILES["fe_photo_image"]["error"];
}
$y = "INSERT INTO photo VALUES (null, '".$filed."', '".$filed1."', '".$hopid."', '".$titleds."')";
$z = mysql_query($y) or die (mysql_error());
if($z) {
$msg = "Data sudah ditambahkan";
}
else {
$msg = "Data tidak bisa dimasukkan";
}
echo print_r($y);
and this is my form:
<form method="post" enctype="multipart/form-data">
<table border="0"cellpadding="0" cellspacing="0" width= "100%">
<tr>
<td>Hop Name :<?echo "$data[hop_name]"?>
<input type='hidden' name='photo_hop_id' value='<?echo"$data[hop_id]"?>'>
</td>
</tr>
<table border="0"cellpadding="0" cellspacing="0" width= "100%">
<tr>
<td cellpadding="0" cellspacing="0" width= "50%">
Near End Site Name : <?echo "$data[ne_site_name]" ?>
</br>
Near End Site Id : <?echo "$data[ne_site_code]" ?>
</td>
<td cellpadding="0" cellspacing="0" width= "50%">
Far End Site Name : <?echo "$data[fe_site_name]" ?>
</br>
Far End Site Id : <?echo "$data[fe_site_code]"?>
</td>
</tr>
<tr>
<td cellpadding="0" cellspacing="0" width= "50%">
<? $pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 1");
$dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]" ?>
<input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :
<input type="file" name="ne_photo_image[]">
</td>
<td cellpadding="0" cellspacing="0" width= "50%">
<?echo "$dpm1[0]"?> : <input type="file" name="fe_photo_image[]">
</td>
</tr>
<tr>
<td cellpadding="0" cellspacing="0" width= "50%">
<? $pm1= mysql_query("SELECT photo_name FROM photo_name WHERE photo_name_id = 2");
$dpm1 = mysql_fetch_array ($pm1);echo"$dpm1[0]" ?>
<input type='hidden' name='photo_name_id[]' value='<?echo"$dpm1[0]"?>'> :
<input type="file" name="ne_photo_image[]">
</td>
<td cellpadding="0" cellspacing="0" width= "50%">
<?echo "$dpm1[0]"?> : <input type="file" name="fe_photo_image[]">
</td>
</tr>
</table>
</table>
<input type="submit" value="insert" />
</form>
many thanks for help
Your error comes clearly from this line :
For example, your var
$filedis an imploded array, which looks like('foo'), ('bar'). Finally, your request will looks likeINSERT INTO photo VALUE (null, '('foo'), ('bar')', [...]);.You must escape simple quotes in
$filed,$filed1,$hopid,$titleds, but I’m pretty sure your request is totally wrong.Can you give us the
phototableschemastructure please ?EDIT :
structure given :
(photo_id,ne_photo_image,fe_photo_image,hop_id,title)To insert multiple rows in a table, you must use this kind of syntax :
Aka, you must insert your datas row by row, not column by column (what you’re trying to attempt right now).
Your code should looks like this (this is definitely not a full piece of code, I’m not sure to understand all your code, then I give you some track) :
Again, this code is far from perfect, I’m just trying to explain you how to approach the problem.