【发布时间】:2012-11-08 21:28:02
【问题描述】:
我正在使用以下代码上传图像文件,当将过程上传到路径时效果很好,但是当文件路径插入到数据库表字段时出现错误
上传者.php
<?php
$db = mysql_connect('localhost', 'root', '') or die('Could not connect:' . mysql_error());
mysql_select_db('fileupload4',$db);
$allowed_filetypes = array('.jpg','.gif','.bmp','.png');
$max_filesize = 10000000;
$upload_path = 'images/';
$filename = $_FILES['userfile']['name'];
$extension = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($extension , $allowed_filetypes)) {
die('The file you attempted to upload is not allowed.');
}
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) {
die('The file you attempted to upload is too large.');
}
if(!is_writable($upload_path)) {
die('You cannot upload to the specified directory, please CHMOD it to 777.');
}
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_path.$filename)) {
echo 'Your file upload was successful, view the file <a href="'.$upload_path.$filename.'" title="Your File">Here</a>';
} else {
echo 'There was an error during the file upload. Please try again.'; // It failed
}
$sql = "UPDATE students SET image = '".$upload_path."' WHERE id = 'student_id'";
mysql_query($sql) OR die(mysql_error());
?>
这是我上传图片时遇到的错误
Unknown column 'id' in 'where clause'
感谢您的帮助...
我的表结构
CREATE TABLE IF NOT EXISTS `students` (
`student_id` int(11) NOT NULL AUTO_INCREMENT,
`image` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
PRIMARY KEY (`student_id`),
KEY `student_id` (`student_id`),
KEY `image` (`image`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
【问题讨论】:
-
看到这种情况发生在你刚刚拿起一个代码而不理解它的情况下,它是我的代码:p 正在使用 id,而你没有,所以它向你显示了这个错误
-
看起来你的 SQL 语法有错误...我想你想要类似 "WHERE student_id = '{valueFromInput}'";"
标签: php mysql sql database file-upload