PDA

View Full Version : upload file problems


Vman
01-19-2005, 03:08 PM
Hello all. I'm having a problem uploading a file to a directory and the name of the file to a database column. I have one file that works and one that doesn't, but the one that doesn't work is almost identical to the one that does.

Here's the first one that just takes one file field and uploads the file to the directory. This one works.
<?php
require_once('Connections/TZA.php');
$uploaddir = 'content/'.$_POST['schedule'];
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
$filename = $_FILES['file']['name'];
$updateSQL = "UPDATE projects SET project_schedule='$filename' WHERE project_id='$proj_id'";

mysql_select_db($database_TZA, $TZA);
$Result1 = mysql_query($updateSQL, $TZA) or die(mysql_error());
$insertGoTo = "project_list.php";
header(sprintf("Location: %s", $insertGoTo));
mysql_close();
?>


Here's the second one that updates the project information in the database and is supposed to upload a new schedule to be used in place of the one uploaded in the first script that works This file doesn't work and I can't seem to figure out why. All of the columns get updated except for project_schedule.
<?php
require_once('Connections/TZA.php');
$uploaddir = 'content/'.$_POST['proj_id']."_".$_POST['client_name'];
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
$filename = $_FILES['file']['name'];
$client = $_POST['client_id'];
$project = $_POST['project_name'];
$login = $_POST['client_login'];
$pword = $_POST['client_password'];
$project = $_POST['proj_id'];
$updateSQL = "UPDATE projects SET client_id='$client',
project_name='$project',
client_login='$login',
client_password='$pword',
project_schedule='$filename' WHERE project_id='$project'";


mysql_select_db($database_TZA, $TZA);
$Result1 = mysql_query($updateSQL, $TZA) or die(mysql_error());
$insertGoTo = "project_list.php";
header(sprintf("Location: %s", $insertGoTo));
mysql_close();
?>

Here's the html for this one
<input name="Submit2" type="submit" value="Update" />
<input name="proj_id" type="hidden" id="proj_id" value="<?php echo $row_rstProjects['project_id']; ?>" />
<input name="schedule" type="hidden" id="schedule" value="<?php echo $row_rstProjects['project_id'].'_'.$row_rstProjects['client_name']; ?>" />
<input name="client_name" type="hidden" id="client_name" value="<?php echo $row_rstProjects['client_name']; ?>" />
Any insite would be greatly appreciated. Thanks.

Vman
01-19-2005, 04:21 PM
Nevermind. Did something stupid as usual. :D

CyanBlue
01-19-2005, 04:36 PM
Which is??? :D

Vman
01-20-2005, 12:05 AM
Well, it was actually a stupidity compilation. :p I originally was going to update the project info from the form page itself. You can't do that if you want to upload a file so I had to direct it to the page with the script you see here. I forgot to take out some left over PHP and chage the form "action" to direct to this page.

Also, if you notice, I am defining the same variable $projects with two different values. oops. :D

CyanBlue
01-20-2005, 12:47 PM
Hm... Gotcha... :)