我制作了一个上传图片的简单表单,但收到了错误消息
'字段列表'中的未知列'images / 16-08-2014-1408177181.jpg'
我从引号中读到问题,但我尝试了很多并收到了同样的错误 这就是项目:
image.php
<form action="saveimage.php" enctype="multipart/form-data" method="post">
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<input name="uploadedimage" type="file">
</td>
</tr>
<tr>
<td>
<input name="Upload Now" type="submit" value="Upload Image">
</td>
</tr>
</tbody></table>
</form>
saveimage.php
<?php
include("config2.php");
?>
<?php
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "images/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload=mysql_query("insert into images_store(images_path,submission_date) Values(`".$target_path."`,`".date("Y-m-d")."`)")or die(mysql_error());
}
}
?>;
config2.php
<?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="db";
$user="root";
$pass="123456";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
$db_selected = mysql_select_db($databasename, $conn);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
}
else
{
die('Not connected : ' . mysql_error());
}
?>
display_messag.php
<?php
include("config2.php");
$select_query = "SELECT 'images_path' FROM 'images_store' ORDER by 'images_id' DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){
?>
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<img src="<?php echo $row["images_path"];="" ?="">" alt="" />">
</td>
</tr>
</tbody></table>
<?php
}
?>
答案 0 :(得分:0)
你应该在VALUES
列表中的字符串值周围加上引号,而不是反引号。
$query_upload=mysql_query("insert into images_store(images_path,submission_date)
values('".$target_path."','".date("Y-m-d")."')")
or die(mysql_error());
SELECT
查询应为:
$select_query = "SELECT `images_path` FROM `images_store` ORDER by `images_id` DESC";
如果您要引用列名或表名,则必须使用反引号,而不是单引号或双引号 - 这些都是在字符串周围使用。
答案 1 :(得分:0)
请忽略VALUES
部分中的反对。像这样
"INSERT INTO `images_store` (`images_path`, `submission_date`) VALUES ('$target_path', '" . date("Y-m-d") . "')"
反引号使您的数据库将其内容解释为字段名称。