Encountered ERROR  | Familiar Sight | | Join Date: Jun 2008 Location: CA
Posts: 222
| | |
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" |  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,751
| | | 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?
|  | Familiar Sight | | Join Date: Jun 2008 Location: CA
Posts: 222
| | | re: Encountered ERROR
It pointed to my sql query - $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}'
-
)";
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,751
| | | re: Encountered ERROR
Are you sure?
The notice is complaining about an index named "approval1".
Where is that being used?
|  | Familiar Sight | | Join Date: Jun 2008 Location: CA
Posts: 222
| | | 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
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,751
| | | 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: -
<form action="process.php" method="post" enctype="multipart/form-data">
-
<input type="file" name="file1" /><br />
-
<input type="file" name="file2" /><br />
-
<input type="submit" />
-
</form>
-
The two files the would be uploaded could be found in the $_FILES array in your proccess.php page: -
<?php
-
$_FILES['file1']; // The first file would be here
-
$_FILES['file2']; // The second would be here.
-
?>
-
Is that what you are looking for?
|  | Familiar Sight | | Join Date: Jun 2008 Location: CA
Posts: 222
| | | 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
:( -
-
$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 -
$query = "INSERT INTO fileStorage (FileName1,FileMime1,FileSize1,FileData1,
-
FileName2,FileMime2,FileSize2,FileData2)
-
VALUES (
-
'{$name1}','{$mime1}',{$size1},'{$data1}',
-
'{$name2}','{$mime2}',{$size2},'{$data2}'
-
)";
-
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,751
| | | 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: -
INSERT INTO myTable (col1, col2, colN) VALUES
-
('value11', 'value12', 'value1N'),
-
('value21', 'value22', 'value2N'),
-
('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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|