By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Encountered ERROR

P: 333
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"
Sep 26 '08 #1
Share this Question
Share on Google+
7 Replies

Expert 5K+
P: 5,058
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?
Sep 26 '08 #2

P: 333
It pointed to my sql query

Expand|Select|Wrap|Line Numbers
  1.         $query = "
  2.             INSERT INTO fileStorage (
  3.                 FileName, FileMime, FileSize, FileData, Created, Description,Author, Requestor, DeadLineFeedback, category
  4.             )
  5.             VALUES (
  6.                 '{$name}', '{$mime}', {$size}, '{$data}', NOW(), '{$description}', UPPER('{$author}'), UPPER('{$requestor}'), '{$DateInput}','{$category}'
  7.             )";
Sep 27 '08 #3

Expert 5K+
P: 5,058
Are you sure?
The notice is complaining about an index named "approval1".

Where is that being used?
Sep 27 '08 #4

P: 333
Hi Atli,

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

Dec 2 '08 #5

Expert 5K+
P: 5,058
You upload multiple files just like you upload a single file, you just use more <input> fields.

For example, using this form:
Expand|Select|Wrap|Line Numbers
  1. <form action="process.php" method="post" enctype="multipart/form-data">
  2.   <input type="file" name="file1" /><br />
  3.   <input type="file" name="file2" /><br />
  4.   <input type="submit" />
  5. </form>
The two files the would be uploaded could be found in the $_FILES array in your proccess.php page:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $_FILES['file1']; // The first file would be here
  3. $_FILES['file2']; // The second would be here.
  4. ?>
Is that what you are looking for?
Dec 3 '08 #6

P: 333
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


Expand|Select|Wrap|Line Numbers
  2.  $name1 = mysql_real_escape_string($_FILES['file1']['name'], $dbLink);
  3.  $mime1 = mysql_real_escape_string($_FILES['file1]['type'], $dbLink);
  4.  $size1 = $_FILES[file1']['size'];
  5.  $data1 = mysql_real_escape_string(file_get_contents($_FILES  ['file1']
  7.  $name2 = mysql_real_escape_string($_FILES['file2']['name'], $dbLink);
  8.  $mime2 = mysql_real_escape_string($_FILES['file2]['type'], $dbLink);
  9.  $size2 = $_FILES['file2']['size'];
  10.  $data2 = mysql_real_escape_string(file_get_contents($_FILES  ['file2']
  11. ['tmp_name']), $dbLink);
and the query

Expand|Select|Wrap|Line Numbers
  1. $query = "INSERT INTO fileStorage (FileName1,FileMime1,FileSize1,FileData1,
  2.     FileName2,FileMime2,FileSize2,FileData2)
  3.             VALUES     (
  4.                     '{$name1}','{$mime1}',{$size1},'{$data1}',
  5.                     '{$name2}','{$mime2}',{$size2},'{$data2}'
  6.                                 )";
Dec 3 '08 #7

Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO myTable (col1, col2, colN) VALUES
  2. ('value11', 'value12', 'value1N'),
  3. ('value21', 'value22', 'value2N'),
  4. ('valueN1', 'valueN2', 'valueNN');
Which you could use to add as many new rows as you like to your table without having to change the structure of it.
Dec 4 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.