Uploaded File Name Into MySQL Table
Posted: Fri Mar 25, 2011 5:13 pm
Hello All,
I wrote a PHP file upload script and I'm trying to figure out how I can get the uploaded file name to be inserted into the MySQL table I created. I've tried several things but nothing works. This is basically an application form I'm working on where users input their info and upload a file.
I'm able to get all of the application info the user submits to the MySQL Table however the uploaded filename isn't getting inserted. Here is a stripped down example of what I have:
Any help you could give would be greatly appreciated! I've posted this question on a few other forums but to no avail.
FYI this doesn't necessarily need to be a perfectly secure code...once I can get it to work the way I need it to then I'll worry about revamping it.
Thanks in advance for your help!
I wrote a PHP file upload script and I'm trying to figure out how I can get the uploaded file name to be inserted into the MySQL table I created. I've tried several things but nothing works. This is basically an application form I'm working on where users input their info and upload a file.
I'm able to get all of the application info the user submits to the MySQL Table however the uploaded filename isn't getting inserted. Here is a stripped down example of what I have:
Code: Select all
<?php
$target_path = "Images/";
$target_path = $target_path . basename($name = $_FILES['pic']['name']);
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$middle_init=$_POST['middle_init'];
mysql_connect("localhost", "My_Username", "My_Password") or die(mysql_error()) ;
mysql_select_db("My_Database") or die(mysql_error()) ;
if (!$_POST['first_name'] | !$_POST['last_name'] | !$_POST['middle_init']) {
header('Location:http://www.mysite.com/error.html');
die();
}
$insert = "INSERT INTO image (first_name, last_name, middle_init, name)
VALUES ('".$_POST['first_name']."', '".$_POST['last_name']."', '".$_POST['middle_init']."', '".$_POST['name']."')";
$add_member = mysql_query($insert);
move_uploaded_file($_FILES['pic']['tmp_name'], $target_path)
?>Thanks in advance for your help!