【发布时间】:2012-08-01 10:10:49
【问题描述】:
我尝试在我的数据库中插入多行,该图像不保存到文件夹和
我得到这个错误
Blockquote ArrayArray 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 'Chrysanthemum.jpg')、('Hydrangeas.jpg')'、'('Chrysanthemum.jpg')、('Hydrangeas.j' 行附近使用正确的语法1
这是我的代码:
$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);
这是我的表格:
<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>
非常感谢您的帮助
【问题讨论】:
-
您是否尝试过回显
$y来检查从代码中填充的查询? -
是的,我回应 $y,我得到了这个:INSERT INTO photo VALUES (null, '('')', '('')', '', '('')')1
-
为什么 99% 的 SO 上有问题的代码完全不可读?
-
@Codemonkey 你是什么意思?
-
@MeijuNainggolan:我的意思是你的代码很乱,缩进很差,而且绝对没有任何有用的 cmets。我没有任何冒犯的意思,但您确实应该清理您的代码,以便更容易发现问题。