Connecting Tech Pros Worldwide Forums | Help | Site Map

Encountered ERROR

ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#1: Sep 26 '08
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's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#2: Sep 26 '08

re: Encountered ERROR


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?
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#3: Sep 27 '08

re: Encountered ERROR


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.             )";
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#4: Sep 27 '08

re: Encountered ERROR


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

Where is that being used?
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#5: Dec 2 '08

re: Encountered ERROR


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
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#6: Dec 3 '08

re: Encountered ERROR


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>
  6.  
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. ?>
  5.  
Is that what you are looking for?
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#7: Dec 3 '08

re: Encountered ERROR


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
  1.  
  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']
  6.  
  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.                                 )";
  7.  
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#8: Dec 4 '08

re: Encountered ERROR


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');
  5.  
Which you could use to add as many new rows as you like to your table without having to change the structure of it.
Reply