Current location: Hot Scripts Forums » Programming Languages » PHP » Trying to write basename to database.


Trying to write basename to database.

Reply
  #1 (permalink)  
Old 01-05-06, 04:07 PM
fompsweeva fompsweeva is offline
New Member
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Trying to write basename to database.

Hello,

I need to take the file name of each file here and write it to the database.

I've tried everything I can think of... now I need your help. Thanks, -Mike

There are three files. Instead of looping the script I just pasted it three times, and changed the uploadimage to uploadimage, uploadimage2, uploadimage3.




PHP Code:

<?

$username
="afakee";
$password="fajeessssssssses";
$database="aggh_ric";

$catid=$_POST['catid'];
$brand=$_POST['brand'];
$description=$_POST['description'];
$price=$_POST['price'];
$intfree=$_POST['intfree'];

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");

$query "INSERT INTO inventory VALUES ('','$catid','$brand','$description','$price','$intfree','$picurl1','$picurl2','$picurl3')";
mysql_query($query);

mysql_close();

// Where the file is going to be placed 
$target_path "images/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path $target_path basename$_FILES['uploadedfile']['name']); 

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];

$target_path "images/";

$target_path $target_path basename$_FILES['uploadedfile']['name']); 

if(
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo 
"The file "basename$_FILES['uploadedfile']['name']). " has been uploaded<br>";
} else{
    echo 
"There was an error uploading the file, please try again!<br>";
}



// Where the file is going to be placed 
$target_path "images/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path $target_path basename$_FILES['uploadedfile2']['name']); 

// This is how we will get the temporary file...
$_FILES['uploadedfile2']['tmp_name'];

$target_path "images/";

$target_path $target_path basename$_FILES['uploadedfile2']['name']); 

if(
move_uploaded_file($_FILES['uploadedfile2']['tmp_name'], $target_path)) {
    echo 
"The file "basename$_FILES['uploadedfile2']['name']). " has been uploaded<br>";
} else{
    echo 
"There was an error uploading the file, please try again!<br>";
}


// Where the file is going to be placed 
$target_path "images/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path $target_path basename$_FILES['uploadedfile3']['name']); 

// This is how we will get the temporary file...
$_FILES['uploadedfile3']['tmp_name'];

$target_path "images/";

$target_path $target_path basename$_FILES['uploadedfile3']['name']); 

if(
move_uploaded_file($_FILES['uploadedfile3']['tmp_name'], $target_path)) {
    echo 
"The file "basename$_FILES['uploadedfile3']['name']). " has been uploaded<br>";
} else{
    echo 
"There was an error uploading the file, please try again!<br>";
}        

?>
Reply With Quote
  #2 (permalink)  
Old 01-06-06, 08:28 AM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Are the files getting uploaded correctly?
If not, are your CHMOD correct for the spicified folder, 'images/', I belive they should be 0777
Is the database getting updated?
Reply With Quote
  #3 (permalink)  
Old 01-06-06, 04:28 PM
fompsweeva fompsweeva is offline
New Member
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
The files are getting uploaded correcty as their original file names..

The database isn't being written to.
Reply With Quote
  #4 (permalink)  
Old 01-06-06, 07:40 PM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Hmm, which values within the SQL statement are designed to be the filenames?
I'm guessing its $picurl1, $picurl2, $picurl3? If so, these are the only variables that aren't getting set prior to the SQL statement taking place.
PHP Code:

$catid=$_POST['catid'];

$brand=$_POST['brand'];
$description=$_POST['description'];
$price=$_POST['price'];
$intfree=$_POST['intfree'];
// Set the pic url variables
$picurl1=$_FILES['uploadedfile']['name'];
$picurl2=$_FILES['uploadedfile2']['name'];
$picurl2=$_FILES['uploadedfile3']['name'];

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");

$query "INSERT INTO inventory VALUES ('','$catid','$brand','$description','$price','$in  tfree','$picurl1','$picurl2','$picurl3')";
mysql_query($query);

mysql_close(); 
I would also recommend executing the SQL statement after the files have been uploaded without any errors, otherwise you might get a few odd records that are missing files.

Last edited by Richard; 01-06-06 at 07:44 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
Unable to write a single quote (') to a MySQL database abtimoteo Perl 1 10-10-05 07:51 AM
Simple, searchable book database max fischer Script Requests 0 05-14-05 01:00 PM
Script for uploading data from local database to production database pual_cruzs PHP 1 07-06-04 12:44 AM


All times are GMT -5. The time now is 06:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.