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