[英]Uploading image in the database using PHP:
It only shows Something went wrong!它只显示出了问题! :(. I've got that code from one site. I don't know where is the problem. The database should be ok also and the code. Can anyone tell me what is wrong? :(。我从一个站点得到了那个代码。我不知道问题出在哪里。数据库也应该没问题,代码也可以。谁能告诉我出了什么问题?
<?php
include 'config.php';
session_start();
if(isset($_POST['button_upload_image'])){
$username=$_SESSION['username'];
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //SQL Injection defence!
$image_name = addslashes($_FILES['image']['name']);
$sql = "INSERT INTO `images` (`image`, `image_name`,`username`)VALUES('$image', '$image_name','$username')";
if (!mysql_query($sql)) { // Error handling
echo "Something went wrong! :(";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
include $main_directory.'parts/header_admin.php';
?>
<?php
include $main_directory.'parts/slider.php';
?>
<?php
include $main_directory.'parts/bottom_menu_hidden.php';
?>
<div class="center_all">
<div class="all_content">
<div class="images_gallery">
<form method="POST" enctype="multipart/form-data">
<label>File: </label>
<input type="file" name="image" />
<input type="submit" name="button_upload_image" />
</form>
</div>
</div>
</div>
<?php
include $main_directory.'parts/footer.php';
?>
</body>
</html>
My database is that:我的数据库是:
CREATE TABLE IF NOT EXISTS `images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`image` blob NOT NULL,
`image_name` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Change this;改变这个;
if (!mysql_query($sql)) { // Error handling
echo "Something went wrong! :(";
}
To this, this will output the real error;为此,这将输出真正的错误;
if (!mysql_query($sql)) { // Error handling
var_dump(mysql_error());
die;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.