Jump to content

Upload image to Database


Vince_M

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/276109-upload-image-to-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.