josephbupe Posted November 4, 2014 Share Posted November 4, 2014 Hi, The following code was written by someone else. It allows me to upload images to a directory while saving image name in the mysql table. I also want the code to allow me save other data (surname, first name) along with the image name into the table, but my try is not working, only the images get uploaded. What am I missing here? if(isset($_POST['upload'])) { $path=$path.$_FILES['file_upload']['name']; if(move_uploaded_file($_FILES['file_upload']['tmp_name'],$path)) { echo " ".basename($_FILES['file_upload']['name'])." has been uploaded<br/>"; echo '<img src="gallery/'.$_FILES['file_upload']['name'].'" width="48" height="48"/>'; $img=$_FILES['file_upload']['name']; $query="insert into imgtables (fname,imgurl,date) values('$fname',STR_TO_DATE('$dateofbirth','%d-%m-%y'),'$img',now())"; if($sp->query($query)){ echo "<br/>Inserted to DB also"; }else{ echo "Error <br/>".$sp->error; } } else { echo "There is an error,please retry or check path"; } } ?> joseph Quote Link to comment https://forums.phpfreaks.com/topic/292260-cant-insert-into-mysql-table/ Share on other sites More sharing options...
josephbupe Posted November 4, 2014 Author Share Posted November 4, 2014 (edited) Ok, I got it working after some modifications: if(isset($_POST['upload'])){ $familyname = trim($_POST['familyname']); $firstname = trim($_POST['firstname']); $othernames = trim($_POST['othernames']); $dateofbirth = trim($_POST['$dateofbirth']); $img = trim($_POST['imgurl']); $path=$path.$_FILES['file_upload']['name']; if(move_uploaded_file($_FILES['file_upload']['tmp_name'],$path)) { echo " ".basename($_FILES['file_upload']['name'])." has been uploaded<br/>"; echo '<img src="gallery/'.$_FILES['file_upload']['name'].'" width="80" height="100"/>'; $img=$_FILES['file_upload']['name']; $query="insert into imgtables (familyname,firstname,othernames,dateofbirth,imgurl,date) values('$familyname','$firstname','$othernames',STR_TO_DATE('$dateofbirth','%d-%m-%y'),'$img',now())"; echo($familyname); if($sp->query($query)){ echo "<br/>Inserted to DB also"; }else{ echo "Error <br/>".$sp->error; } } else { echo "There is an error,please retry or ckeck path"; } } I am trying to convert to prepared statement. Regards. Joseph Edited November 4, 2014 by josephbupe Quote Link to comment https://forums.phpfreaks.com/topic/292260-cant-insert-into-mysql-table/#findComment-1495674 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.