Jump to content

Recommended Posts

Hey everyone,

 

I posted something similar to this before and thought I had received an answer, but for whatever reason, the script I wrote had inconsistent functionality. It would work sometimes, but not others.

 

At any rate I had to completely revamp the script. Now I'm having the same initial problem with this new script. Basically, what I'm trying to do is get my PHP script to upload a file, insert form info into the MySQL Database Table, and insert the name of the uploaded file into the MySQL Database table as well.

 

I've been able to get everything to work except inserting the name of the uploaded file into the MySQL Database table. I'll show you what I have currently (a stripped down version anyway) then any suggestions you could give would be much appreciated! Please help! I've been working on this for the past month and keep running into issues:

 

<?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)

?>

<HTML>
<HEAD>
<TITLE>My Site</TITLE>

 

HTML "Confirmation Script" continues on from there.  Like I said before, everything works except the name of the uploaded file doesn't get inserted into the MySQL table.  :shrug: Oh...that specific field in the MySQL table is titled "name".

 

Anyway, again, any help you could give would be awesome!

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/231463-uploaded-file-name-into-mysql-table/
Share on other sites

Besides inserting data directly to mysql.....you should sanitize that.

 

Can you echo out each value and make sure they actually have values.

 

I personally make them all into variable and then place those into the mysql inserts.

 

example

$name = $_FILES['pic']['name'];

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.