Encountered ERROR

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    Encountered ERROR

    Anybody have ever encounter the error below and what's the meaing of it?This happens when I upload a file using the PHP on my SQL.

    "Notice: Undefined index: approval1 in Vol3:/DM/add_file2.php on line 150"
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    This isn't technically and error. It's a notice.
    The message really says it all.

    Your code is trying to read an undefined array index on line 150 of your code, called "approval1" .

    I'm guessing, since this has something to do with file uploads, that this index is being read from the $_POST super-global, but the field in question has either not been posted, or was left out in your <form>.

    What does line 150 of your code look like?

    Comment

    • ddtpmyra
      Contributor
      • Jun 2008
      • 333

      #3
      It pointed to my sql query

      Code:
              $query = "
                  INSERT INTO fileStorage (
                      FileName, FileMime, FileSize, FileData, Created, Description,Author, Requestor, DeadLineFeedback, category
                  )
                  VALUES (
                      '{$name}', '{$mime}', {$size}, '{$data}', NOW(), '{$description}', UPPER('{$author}'), UPPER('{$requestor}'), '{$DateInput}','{$category}'
                  )";
      Last edited by Markus; Dec 2 '08, 11:37 PM. Reason: fixed code tags

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Are you sure?
        The notice is complaining about an index named "approval1" .

        Where is that being used?

        Comment

        • ddtpmyra
          Contributor
          • Jun 2008
          • 333

          #5
          Hi Atli,

          Just a follow up question on your code was posted on 'How to' section, how can I do multiple upload this time?

          thanks,
          DM

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            You upload multiple files just like you upload a single file, you just use more <input> fields.

            For example, using this form:
            [code=html]
            <form action="process .php" method="post" enctype="multip art/form-data">
            <input type="file" name="file1" /><br />
            <input type="file" name="file2" /><br />
            <input type="submit" />
            </form>
            [/code]
            The two files the would be uploaded could be found in the $_FILES array in your proccess.php page:
            [code=php]
            <?php
            $_FILES['file1']; // The first file would be here
            $_FILES['file2']; // The second would be here.
            ?>
            [/code]
            Is that what you are looking for?

            Comment

            • ddtpmyra
              Contributor
              • Jun 2008
              • 333

              #7
              I did this first adding of couse the additional input form for th user to browse, then I tried putting it on my variables like below but didn't work

              :(

              Code:
                     
               $name1 = mysql_real_escape_string($_FILES['file1']['name'], $dbLink);
               $mime1 = mysql_real_escape_string($_FILES['file1]['type'], $dbLink);
               $size1 = $_FILES[file1']['size'];
               $data1 = mysql_real_escape_string(file_get_contents($_FILES  ['file1']
              
               $name2 = mysql_real_escape_string($_FILES['file2']['name'], $dbLink);
               $mime2 = mysql_real_escape_string($_FILES['file2]['type'], $dbLink);
               $size2 = $_FILES['file2']['size'];
               $data2 = mysql_real_escape_string(file_get_contents($_FILES  ['file2']
              ['tmp_name']), $dbLink);
              and the query

              Code:
              $query = "INSERT INTO fileStorage (FileName1,FileMime1,FileSize1,FileData1,
              	FileName2,FileMime2,FileSize2,FileData2)
                          VALUES 	(
                                  '{$name1}','{$mime1}',{$size1},'{$data1}',
                                  '{$name2}','{$mime2}',{$size2},'{$data2}'
                                              )";

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                That's not a very good way to do this.
                Your query would essentially require you to duplicate each column of the table for each additional file, which would cause all sorts of problems.

                What you should be doing is add a new row for each file, not new columns to each row for each new file.

                A multiple insert query should look like:
                [code=mysql]
                INSERT INTO myTable (col1, col2, colN) VALUES
                ('value11', 'value12', 'value1N'),
                ('value21', 'value22', 'value2N'),
                ('valueN1', 'valueN2', 'valueNN');
                [/code]
                Which you could use to add as many new rows as you like to your table without having to change the structure of it.

                Comment

                Working...