lauren_etherington Posted February 5, 2014 Share Posted February 5, 2014 (edited) Hello PHPer's I am having a few problems with my code. I've probably missed something but could do with an outsiders opinion. Basically, I am writing a bit of code where the user can enter some information and an image into a form and save it to the mysql database. For the most part, the code works, If I don't add the image then the content is all saved. However, when I do add an image I am just given my predefined error message from the code. The php debugger is not much use as the connection is for a local host which is stored on a server and not on my PC.... This is the code: $auth = $_POST['auth']; $tit = $_POST['tit']; $band = $_POST['band']; $alb = $_POST['alname']; $rel = $_POST['release']; $stat = $_POST['stat']; $shrt = $_POST['short']; $art = $_POST['art']; $conn = mysqli_connect("localhost","") or die ("Could not connect to database"); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } else { if ($_FILES['file']['type'] != "image/gif" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/jpg" && $_FILES['file']['type'] != "image/x-png" && $_FILES['file']['type'] != "image/png") { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } else { $finame = $_FILES["file"]["name"]; //$ext = end(explode(".", $finame)); $result = move_uploaded_file($_FILES['file']['tmp_name'], "../includes/$finame"); if ($result == 1) { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status,image) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat''$finame'))"; //echo "$naquery"; } else { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } } } $result = mysqli_query($conn, $query); if($result){ echo "successful"; echo "<BR>"; echo "<a href='http://'>Back to Content Management </a>"; } else { echo "error could not upload article"; echo "<BR>"; echo "<a href='http://'>Back to Content Management </a>"; } mysqli_close($conn); ?> Any help on getting this to upload the image files would be much appreciated. Thanks Edited February 5, 2014 by lauren_etherington Quote Link to comment https://forums.phpfreaks.com/topic/285963-saving-an-image-file-to-mysql-database/ Share on other sites More sharing options...
Solution Barand Posted February 5, 2014 Solution Share Posted February 5, 2014 looks like a comma missing VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat''$finame')) ^ comma? Quote Link to comment https://forums.phpfreaks.com/topic/285963-saving-an-image-file-to-mysql-database/#findComment-1467860 Share on other sites More sharing options...
lauren_etherington Posted February 5, 2014 Author Share Posted February 5, 2014 I knew it was something little and stupid!!! I feel a bit silly now haha. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/285963-saving-an-image-file-to-mysql-database/#findComment-1467861 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.