Vince_M Posted March 25, 2013 Share Posted March 25, 2013 I am trying to upload an image to a images folder and also add the image name to the database. I am able to upload the image but cannot upload the name to the database. Also with the database I fill everything out and add it to the database and everything is fine (except for the image name) but I am getting blank records along with a filled out record (I don't have the slightest idea why this is happening). Please see the code below. If anyone can point me in the right direction for both of my questions I would greatly appreciate it. Thank you in advance. Create table php <?php include ("db_connect.php"); ?> <?php //select the database in which to add a table mysql_select_db("final_exam_db",$con); $sql = "CREATE TABLE drivers_0115061 (id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), fn varchar(15), ln varchar(15), month varchar(9), day int, year int, name varchar(30), email varchar(40) )"; mysql_query($sql,$con); echo mysql_error(); ?> <?php include ("db_close.php"); ?> Add driver php <?php include("db_connect.php");?> <?php // select the database in which to add a table mysql_select_db("final_exam_db",$con); $sql ="INSERT INTO drivers_0115061 (ln,fn,month,day,year,name,email) VALUES ('".$_POST["ln"]."', '".$_POST["fn"]."', '".$_POST["month"]."', '".$_POST["day"]."', '".$_POST["year"]."', '".$_POST['file']['name']."', '".$_POST["email"]."' )"; mysql_query($sql, $con); echo mysql_error(); ?> <?php include("image_upload.php");?> <?php include("db_close.php");?> image upload php <?php $target_folder="images/"; $target_file=$target_folder.basename($_FILES["photo"]["name"]); if(move_uploaded_file($_FILES["photo"]["tmp_name"],$target_file)) { // echo "It Worked!"; echo "<a href='".$target_file."'target='phpfinalexam2013.php'/>".$target_file."</a>"; } // else // { // echo "Crap No Go!"; // } ?> Vince_M Quote Link to comment https://forums.phpfreaks.com/topic/276109-upload-image-to-database/ Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 Please use code tags around your code. You can do this using the <> button in the editor. Quote Link to comment https://forums.phpfreaks.com/topic/276109-upload-image-to-database/#findComment-1420838 Share on other sites More sharing options...
Barand Posted March 25, 2013 Share Posted March 25, 2013 The uploaded file name will be in the $_FILES array, not the $_POST array. ie $_FILES["photo"]["name"] Quote Link to comment https://forums.phpfreaks.com/topic/276109-upload-image-to-database/#findComment-1420917 Share on other sites More sharing options...
Vince_M Posted March 25, 2013 Author Share Posted March 25, 2013 I will try that tonight. How about my getting the blank records? That one I can't think of why at all. Quote Link to comment https://forums.phpfreaks.com/topic/276109-upload-image-to-database/#findComment-1420932 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.