Forum Moderators: coopster

Message Too Old, No Replies

variable undefined error?

         

rekhad

10:17 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



when i submit the form I get an error that $userfile is undefined in loadmeup.php.Can I get help from you all?

<form enctype="multipart/form-data" action="loadmeup.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="300000">
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" />
</form>

loadmeup.php

<html>
<body>
<h1>Enter Name and Descriptions of Pics</h1>
<form action="view.php" method="post">
<?php
$dbh=mysql_connect("localhost", "username", "password") or die ('I cannot connect to the database.');
mysql_select_db("db");

$uploaddir = '/home/username/public_html/images/';
$tot = count($userfile);
$num = 0;
if ($_FILES['userfile']['name'][$q] == "") continue;
$num = $num + 1;
$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);

while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;
$new_pic = "$new_id.jpg";
}
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir . $new_pic)) {
$sql = "INSERT INTO pics ( pic_id , pic_name , descrip )VALUES ('$new_id', NULL , NULL);";
mysql_query($sql);
} else {
print "<strong>($_FILES{['userfile']}{['name']}[$q])</strong> did not upload!";
}

<strong><?=$_FILES['userfile']['name'][$q]?></strong><br /><br />
<strong>Name:</strong><br />
<input type="text" name="pic_name[<?=$num>]" /><br /><br />
<strong>Description:</strong><br />
<textarea name="descrip[<?=$num?>]"></textarea>
<input type="hidden" name="pic_id[<?=$num?>]" value="<?=$new_id?>" />

<?php
}
?>
<input type="submit" value="Click to Save Descriptions" />
</form>
</body>
</html>

----
---
---

StupidScript

10:42 pm on Mar 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless
register_globals
is turned on in php.ini or using another method

$tot = count($userfile);

is asking to count the values in an undefined variable. Try:

$tot = count($_POST['userfile']);

to access the array for counting as you did later on with the FILES array.

rekhad

10:49 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



I have changed it to
$tot=count($_POST['userfile'];
but still I am getting error at the same line?

jatar_k

10:56 pm on Mar 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this one

$tot = count($_FILES['userfile']);

rekhad

12:24 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Thanks that worked.But now some more errors after that line.I am trying..

rekhad

12:31 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Now I have the following errors?

Notice: Undefined variable: new_pic in c:\program files\easyphp1-8\www\loadmeup.php on line 27

Warning: move_uploaded_file(c:\Progarm Files\EasyPHP-1.8\www\images): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\loadmeup.php on line 27

Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php97.tmp' to 'c:\Progarm Files\EasyPHP-1.8\www\images' in c:\program files\easyphp1-8\www\loadmeup.php on line 27
(Array{['userfile']}{['name']}[0]) did not upload! //
// // // Bulls.jpg

Name:

Description:
//

Notice: Undefined variable: new_pic in c:\program files\easyphp1-8\www\loadmeup.php on line 27

Warning: move_uploaded_file(c:\Progarm Files\EasyPHP-1.8\www\images): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\loadmeup.php on line 27

Warning: move_uploaded_file(): Unable to move 'C:/Program Files/EasyPHP1-8\tmp\php98.tmp' to 'c:\Progarm Files\EasyPHP-1.8\www\images' in c:\program files\easyphp1-8\www\loadmeup.php on line 27
(Array{['userfile']}{['name']}[1]) did not upload! //
// // // Henry.jpg

Name:

Description:
//

jatar_k

1:29 am on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when correcting errors always start at the top and work from there

Notice: Undefined variable: new_pic in c:\program files\easyphp1-8\www\loadmeup.php on line 27

what's line 27?

rekhad

2:33 am on Mar 8, 2006 (gmt 0)

10+ Year Member



My line 27 is

if (move_uploaded_file($_FILES['userfile']['tmp_name'][$q], $uploaddir.$new_pic)) {

jatar_k

3:02 am on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so that variable comes from here

$sql = "SELECT pic_id FROM pics ORDER BY pic_id DESC LIMIT 1";
$result = mysql_query($sql);

while($i = mysql_fetch_array($result)){
$new_id = $i['pic_id'] + 1;
$new_pic = "$new_id.jpg";
}

I can only guess that something isn't working with the mysql part of that

rekhad

3:29 am on Mar 8, 2006 (gmt 0)

10+ Year Member



I am not able to resolve it?

Also I have created a directory
'C:\Program Files\EasyPHP-1.8\www\images';
but why it says no such directory found?

Warning: move_uploaded_file(C:\Program Files\EasyPHP-1.8\www\images): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\loadmeup.php on line 28

rekhad

3:07 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



any help on my last post?

jatar_k

4:51 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I wonder if it is just a windows path issue

maybe try to use a folder like this

C:\img\

and see if that makes any difference