...

View Full Version : Undefined Index mysql query



SeattleMicah
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']."'");




<?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($fp1, filesize($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-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/).

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

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

Notice: Undefined index: ______

Inigoesdr
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']){



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum