Page 1 of 1

upload attachment function.....HELP ME!!!!due date 11/11/06!

Posted: Thu Nov 09, 2006 4:08 am
by rathu
JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys, I need some help here .....i don't seem to find a way to make this happen ...my project is a simple task management system....my problem is how do insert all the task details simultaneously with attach documents below....because in this file, there are 2 forms which is 1st to insert the task details, 2nd is to upload attachment...both work well if filed seperately...but now I need to attach the uploaded document to the respective Task_ID...FYI Task_ID is an auto increment...any suggestion to simplify the function or reconstruct my code would be helpful..I know my code is a mess...here is my some code in Add_Task.php...

Code: Select all

<?
session_start();
?>
<? $User_ID =$_SESSION['User_ID'];?>
<?php include("config.php");?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ADD NEW TASK</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

  <tr>
    <td height="546"></td>
    <td colspan="2" valign="top" bgcolor="#0066FF"><form name="form1" method="post" action="After_Add_Task.php">
        <table width="100%" border="1">
          <tr bordercolor="#000000">
            <td width="18%"><strong>Date Assigned</strong></td>
            <td width="2%">:</td>
            <td width="80%"><input type="text" name="Date_Assigned" value="<? print(date("dS F, Y")); ?>" readonly="true"></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Due Date </strong></td>
            <td width="2%">:</td>
            <td width="80%"><input type="text" name="Due_Date" size="20" value="<? printf($Due_Date);?>" ></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Raised By</strong></td>
            <td width="2%">:</td>
            <td width="80%"><input type="text" name="Raised_By" value="<?php print($User_ID);?>" readonly="true"></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Status</strong></td>
            <td width="2%">:</td>
            <td width="80%"><SELECT name="Status">
                <OPTION SELECTED>New</OPTION>
                <OPTION>Pending</OPTION>
                <OPTION>Completed</OPTION>
              </SELECT></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Priority</strong></td>
            <td width="2%">:</td>
            <td width="80%"><SELECT name="Priority">
                <OPTION SELECTED>High</OPTION>
                <OPTION>Medium</OPTION>
                <OPTION>Low</OPTION>
              </SELECT></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Assigned To</strong></td>
            <td width="2%">:</td>
            <td width="80%"><SELECT name="Assigned_To">
                <?

         $result = mysql_query("select * from user");

         while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         ?>
                <option value="<? echo $row["User_ID"];?>"><? echo $row["User_ID"];?></option>
                <?
      }
      mysql_free_result($result);
   
      ?>
              </SELECT></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Description</strong></td>
            <td width="2%">:</td>
            <td width="80%"><textarea name="Description" rows=7 cols=70></textarea></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Remarks</strong></td>
            <td width="2%">:</td>
            <td width="80%"><textarea name="Remarks" rows=7 cols=70></textarea></td>
          </tr>
          <tr bordercolor="#000000">
            <td width="18%"><strong>Attachment</strong></td>
            <td width="2%">:</td>
            <td width="80%">
            </td>
          </tr>
          <p></p>
        </table>
      <label for="file">Filename:</label>
<form enctype="multipart/form-data" action="2.php" method="POST">
  <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <input name="button" type="file" value="Browse"/>
    <input type="submit" value="Send File" />

        <input type="submit" name="button" value="Submit">
        <input type="submit" name="button" value="Cancel">
        <input type="submit" name="button" value="Reset">
      </form></td>
    <td></td>
    <td></td>
  </tr>
 
</body>
</html>

JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Nov 09, 2006 6:20 am
by Mordred
1. Use just one form.
2. If you need to be able to attach other documents to the same task later, generate a different form (only file upload) and pass the id of the task as a hidden field.

Posted: Thu Nov 09, 2006 9:08 am
by Obadiah
also you may not want to use those short php tags

Code: Select all

<?php 
// your code
?>
use these instead....in my own experience i found that you run unto less problem down the road :)

plz....help me...i cant even think of the code right now....

Posted: Thu Nov 09, 2006 8:53 pm
by rathu
the requirement for system is actually like this:

1.the initial value of the "browse" flag is "0", when user click the "browse" button,
the flag of the browse button should be "1" and system would post and save the all the task details
into database and $Task_ID would be created for the Task.(Task_ID is auto_incremented)

2.Then user select file and click "send file" button, the system will upload the selected file and
copy into the specified folder and also attach it to the $Task_ID.

3.Then user click the "submit" button, system should check the browse flag,

[INDENT] if "1", system will go to other page and display previous task details and also the attachment.[/INDENT]

[INDENT]if the flag "0", this means that the task has no attachment and the system will save all the task details
then go to other page and display the previous task details that has no attachment.[/INDENT]

3.If user has already click "browse" button and "send file", then the user decided to cancel the task ,
or click anywhere except "cancel" button, system will check for the "browse" flag ,

[INDENT]if "1", system will prompt(push) user to click "cancel" button. Once user has click the "cancel" button,
the system will delete the task according to $Task_ID and clear the page.
[/INDENT]

if "0" the page will be refreshed.

4.For the "Reset" button,I guess the function is the same with "cancel" button.so there is no need
to include "Reset" button.