CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Undefined Index mysql query (http://www.codingforums.com/showthread.php?t=276298)

SeattleMicah 10-12-2012 10:30 PM

Undefined Index mysql query
 
I am trying to implement a upload script can you please help me debug my errors? DB users TABLE images.

Notice: Undefined index: img in C:\wamp\www\workfun\myaccount.php on line 64

PHP Code:

$result mysql_query("SELECT * FROM images WHERE img='".$_GET['img']."'"); 



PHP Code:

<?php 


//connect to database. Username and password need to be changed 
mysql_connect("localhost""root""Superfad11"); 

//Select database, database_name needs to be changed 
mysql_select_db("users"); 

if (!
$_POST['uploaded']){ 
//If nothing has been uploaded display the form 
?> 

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"  
ENCTYPE="multipart/form-data"> 
Upload:<br><br> 
<input type="file" name="image"><br><br> 
<input type="hidden" name="uploaded" value="1"> 
<input type="submit" value="Upload"> 
</form> 

<? 
}else{ 
//if the form hasn't been submitted then: 

//from here onwards, we are copying the file to the directory you made earlier, so it can then be moved  
//into the database. The image is named after the persons IP address until it gets moved into the database 

//get users IP 
$ip=$REMOTE_ADDR

//don't continue if an image hasn't been uploaded 
if (!empty($image)){ 

//copy the image to directory 
copy($image"./temporary/".$ip.""); 

//open the copied image, ready to encode into text to go into the database 
$filename1 "./temporary/".$REMOTE_ADDR
$fp1 fopen($filename1"r"); 

//record the image contents into a variable 
$contents1 fread($fp1filesize($filename1)); 

//close the file 
fclose($fp1); 

//encode the image into text 
$encoded chunk_split(base64_encode($contents1));  

//insert information into the database 
mysql_query("INSERT INTO images (img,data)"."VALUES ('NULL', '$encoded')"); 

//delete the temporary file we made 
unlink($filename1); 


//end 

?>


Fou-Lu 10-12-2012 11:19 PM

This query isn't in here anywhere.
The error is simple: you have no img offset in your $_GET superglobal. Since you didn't post that code, we can't help you with that.

On the other hand, this other code is ancient. It relies on register globals which are now gone. $REMOTE_ADDR and $image will not exist for use as of 5.4, and will only exist if register_globals are explicitly enabled as of 4.2.0.
Code wise there is no reason to move or copy this file if you are storing it in a db. Simply read and passthru it from the temporary location (that is, where $_FILES is stored, not where you created the ./temporary/).

SeattleMicah 10-12-2012 11:41 PM

sorry for wasting both of our time, im going to find a better script.

SeattleMicah 10-13-2012 12:18 AM

every upload script I use I get the error

Notice: Undefined index: ______

Inigoesdr 10-13-2012 01:45 AM

Quote:

Originally Posted by SeattleMicah (Post 1279276)
every upload script I use I get the error

Notice: Undefined index: ______

That error is caused by trying to access an array element that doesn't exist, such as this line:
PHP Code:

if (!$_POST['uploaded']){ 

That should be checked like this:
PHP Code:

if (!isset($_POST['uploaded']) || !$_POST['uploaded']){ 



All times are GMT +1. The time now is 12:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.