First!, I have investigated so many similar posts on the site about this title : "Upload image to mysql using php", but did not get my answer.
I am coding a php script to post images from html form to mysql database. please help me fixed it because it is not working. tnx
this is html form
<form name="main_form" action="main.php" method="post" enctype="multipart/form-data">
<input type="text" name="title" >
<input type="file" name="img" ><br/>
<input type="text" name="body" >
<input type="text" name="link" >
<input type="text" name="linktext" >
<input type="submit" value="submit">
</form>
this is main.php
if(isset($_POST['title'])){
$sql="INSERT INTO main (title, img, body, link, linktext)
VALUES
('$_POST[title]','','$_POST[body]','$_POST[link]','$_POST[linktext]')";
if (!mysql_query($sql,$con)){
die('Error: ' . mysql_error());}
if ($_FILES['img']['tmp_name'] != ''){
$image = addslashes(file_get_contents($_FILES['img']['tmp_name']));
if ($image == ''){
echo 'Image type not supported';
} else {
$query = "UPDATE main SET img='$image' WHERE title='$title'";
$result = mysql_query($query);
var_dump($result);
if ($result){
echo 'Image scaled and uploaded';
} else {
echo 'Error running the query';}
}
}
$alert='record inserted';
echo '<script>alert("'.$alert.'");</script>';
};
img in database has type=BLOB record inserts successfully in database but img field (BLOB) has nothing in it and is always 0 bytes.
var_dump($result);
will display: boolean false
I am getting this message at the display: Error running the query
please help!
Thanks :)
echo 'Error running the query';
the following line:echo mysql_error();
and update your post with returned error. – Spiritfyre Jul 9 '12 at 7:17echo $title;
before your update sql line. – Lake Jul 9 '12 at 7:18