saving path in the database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

saving path in the database

Post by franknu »

Can anyone tell me why is not working.

the problem is that file is being uploaded on a diffrent folder
and it is not saving the path in the database

i want the file to be upload it in this folder

("/home/townsfin/public_html/business_images/ ")

and instead it is being send to this folder

("/home/townsfin/public_html/")

on top of that it is not saving the path in the database for the file

here is my code

Code: Select all

<?php 
         
         

$uploaddir = realpath ("/home/townsfin/public_html/business_images/ "); 
$uploadfile = $uploaddir . basename($_FILES['Picture1']['name']); 

if(!empty($_FILES['Picture1'])) 
{ 
    var_dump($uploaddir); 
     
    var_dump($_FILES['Picture1']['size']); 
    var_dump($_FILES['Picture1']['error']); 
    var_dump($_FILE); 
    var_dump($_FILES['Picture1']['type']); 
     var_dump($_FILES['Picture1']['name']); 
     
      } 

   if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $uploaddir .$_FILES['Picture1']['name'])) 
     
    { 
       echo("File Uploaded"); 
       echo("$uploaddir"); 
       echo("$uploadfile"); 
   } 
     
   else 
     
   { 
       echo ("file no uploaded!"); 
       print_r($_FILES); 
       echo realpath('./'); 
   } 


   

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What are all those var_dump() calls telling you?
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

well info such as size

bool(false) int(29457) int(0) NULL string(9) "image/gif" string(30) "christmas-bells-with-holly.gif" File Uploadedchristmas-bells-with-holly.gif
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I suppose more specifically I should ask what var_dump($uploaddir); is telling you.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

ok it is bring the file where i want the only problem now is tha it is not saving the path in the database

Code: Select all

<?php
$uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here
$uploadfile = $_FILES['Picture1']['name']; // No need for basename() here

if(!empty($_FILES['Picture1'])){
   var_dump($uploaddir); 
     
   var_dump($_FILES['Picture1']['size']); 
   var_dump($_FILES['Picture1']['error']); 
   var_dump($_FILE); 
   var_dump($_FILES['Picture1']['type']); 
   var_dump($_FILES['Picture1']['name']); 
} 

$fullpath = $uploaddir . $uploadfile;
if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){ 
   echo("File Uploaded"); 
   echo("$uploaddir"); 
   echo("$uploadfile"); 
} 
else { 
   echo ("file no uploaded!"); 
   print_r($_FILES); 
   echo realpath('./'); 
}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

franknu wrote:ok it is bring the file where i want the only problem now is tha it is not saving the path in the database
Where's the code for putting the file path into the database?
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

ok, i thought that this would automaticly would do so just because i have a colum call Picture1
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

8O No, a file upload does not do something like that automagically.
What type of database are you using? What do you want to store, where and when?
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

Code: Select all

$uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here
$uploadfile = $_FILES['Picture1']['name']; // No need for basename() here

if(!empty($_FILES['Picture1'])){
   var_dump($uploaddir); 
     
   var_dump($_FILES['Picture1']['size']); 
   var_dump($_FILES['Picture1']['error']); 
   var_dump($_FILE); 
   var_dump($_FILES['Picture1']['type']); 
   var_dump($_FILES['Picture1']['name']); 
} 

$fullpath = $uploaddir . $uploadfile;

if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){ 
   echo("File Uploaded"); 

   $sql="INSERT INTO `business_info` where `Picture1`=`Picture1` // this is where i want the file path to go to
} 
else { 
   echo ("file no uploaded!"); 
   print_r($_FILES); 
   echo realpath('./'); 
}
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

this is my error message

Code: Select all

Parse error: syntax error, unexpected T_STRING in /home/townsfin/public_html/html_forms/insert_data.php on line 142
thank you
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Show lines 140 to 150 of your code please.
franknu
Forum Contributor
Posts: 146
Joined: Sun May 28, 2006 9:29 am

Post by franknu »

$sql="INSERT INTO `business_info` where (`Picture1`=`Picture1`)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$sql="INSERT INTO `business_info` where `Picture1`=`Picture1` // this is where i want the file path to go to
it's missing a " to end the string literal.
An INSERT statement has no WHERE clause.
You have to send the sql statement to the database.
What type of database do you use? (possible answers: mysql, postgresq, sqlite, mssql ....)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

MySQL syntax for INSERT queries.

Code: Select all

INSERT INTO `tableName` (`fieldName1`, `fieldName2`, `fieldName3`) VALUES (intValue, 'strValue', '#dateValue#');
Post Reply