View Full Version : Undefined Index mysql query

10-12-2012, 11:30 PM
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

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


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

//Select database, database_name needs to be changed

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

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

//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

//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($fp1, filesize($filename1));

//close the file

//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


10-13-2012, 12:19 AM
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/).

10-13-2012, 12:41 AM
sorry for wasting both of our time, im going to find a better script.

10-13-2012, 01:18 AM
every upload script I use I get the error

Notice: Undefined index: ______

10-13-2012, 02:45 AM
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:

if (!$_POST['uploaded']){
That should be checked like this:

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