Bopo Posted April 1, 2009 Share Posted April 1, 2009 Hi Well I really don't know where to go from this, but basically I'm getting no errors, and the pages refreshes but there are never any new records, therefore it's not working, but I don't know what else to do <?php if(isset($_POST['submit'])) { include ("blogconnect.php"); if(isset($_FILES['image']) && $_FILES['image']['size'] > 0) { // Temporary file name stored on the server $tmpName = $_FILES['image']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); $sql = "INSERT INTO userimage (image) VALUES ('$data')"; $query = mysql_query($sql, $connect); echo 'Your image has been uploaded!'; } else echo 'No image selected or uploaded'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152008-solved-image-not-saving-into-mysql-database/ Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 Change this line to and tell me if you see any errors when you try to insert again. $query = mysql_query($sql, $connect) or die(mysql_error()); You are also missing a '}' from your first if statement. Quote Link to comment https://forums.phpfreaks.com/topic/152008-solved-image-not-saving-into-mysql-database/#findComment-798311 Share on other sites More sharing options...
Bopo Posted April 1, 2009 Author Share Posted April 1, 2009 Many thanks for your help, everything seems to act exactly the same, however it's my form I believe could be the issue <form enctype="multipart/form-data" form id="form1" name="form1" method="post" action="" class="form"> <input name="MAX_FILE_SIZE" value="1002400" type="hidden"> <input name="image" accept="image/jpeg" type="file"> <input value="Submit" type="submit"> </form> I am checking that I'm only trying to upload a jpeg, and it's quite a small image, as I don't know the unit of measurement for the max file size value. Quote Link to comment https://forums.phpfreaks.com/topic/152008-solved-image-not-saving-into-mysql-database/#findComment-798319 Share on other sites More sharing options...
chmpdog Posted April 1, 2009 Share Posted April 1, 2009 for future reference, I found the easiest way to find an error when modifying a table is echo your variable ("$sql" in this case). Quote Link to comment https://forums.phpfreaks.com/topic/152008-solved-image-not-saving-into-mysql-database/#findComment-798360 Share on other sites More sharing options...
Bopo Posted April 1, 2009 Author Share Posted April 1, 2009 Thanks for the help, managed to get it working Quote Link to comment https://forums.phpfreaks.com/topic/152008-solved-image-not-saving-into-mysql-database/#findComment-798373 Share on other sites More sharing options...
Maq Posted April 1, 2009 Share Posted April 1, 2009 Thanks for the help, managed to get it working Hmm yeah, file uploading scripts can be tricky sometimes. Quote Link to comment https://forums.phpfreaks.com/topic/152008-solved-image-not-saving-into-mysql-database/#findComment-798377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.