I am trying to store image on my mysql database. I know that it may not be the smartest thing to do, but this job requires it. I have looked online on how to store an image using php code, however every time I try to follow the guidelines it seems like a random problem pops up. With this code am using right now, I've managed to get all the information stored in the database except the image and the image name. Any suggestions on how to make it work?
$connect = mysqli_connect("host", "user", "pass", "dbname");
if(!empty($_POST))
{
$output = '';
$title = mysqli_real_escape_string($connect, $_POST["title"]);
$image = addslashes($_FILES['image']['tmp_name']);
$name = addslashes($_FILES['image']['name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$text2 = mysqli_real_escape_string($connect, $_POST["text2"]);
$text1 = mysqli_real_escape_string($connect, $_POST["text1"]);
$dtime = date('Y-m-d H:i:s');
$query = "
INSERT INTO news(title, image, name, text2, text1, dtime)
VALUES('$title', '{$image}', '$name', '$text2', '$text1', '$dtime');
";
I have tried different options, adding $connect into $image and $name to make it like the rest or changing addslashes into mysql_real_escape_string.
I need some help to get it to work,if you have the time I'll appreciate it!