我使用上传的图像文件,在上传过程时,工作路径以及下面的代码,但是当文件路径插入到数据库表字段我得到错误PHP数据库文件上传错误
uploader.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 ;
见这种情况whenn你只要拿起一个代码不理解它,它的我的代码:对正在使用的ID,你是不是,所以它显示你这个错误 –
看起来像你的SQL语法错误。我想你想要的东西像“WHERE student_id ='{valueFromInput}'”;“ –