Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-12-2012, 10:30 PM   PM User | #1
SeattleMicah
Regular Coder

 
Join Date: Dec 2011
Posts: 201
Thanks: 12
Thanked 26 Times in 26 Posts
SeattleMicah is an unknown quantity at this point
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 

?>
__________________
http://getfirebug.com/

Last edited by SeattleMicah; 10-12-2012 at 10:55 PM..
SeattleMicah is offline   Reply With Quote
Old 10-12-2012, 11:19 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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/).
Fou-Lu is offline   Reply With Quote
Old 10-12-2012, 11:41 PM   PM User | #3
SeattleMicah
Regular Coder

 
Join Date: Dec 2011
Posts: 201
Thanks: 12
Thanked 26 Times in 26 Posts
SeattleMicah is an unknown quantity at this point
sorry for wasting both of our time, im going to find a better script.
__________________
http://getfirebug.com/
SeattleMicah is offline   Reply With Quote
Old 10-13-2012, 12:18 AM   PM User | #4
SeattleMicah
Regular Coder

 
Join Date: Dec 2011
Posts: 201
Thanks: 12
Thanked 26 Times in 26 Posts
SeattleMicah is an unknown quantity at this point
every upload script I use I get the error

Notice: Undefined index: ______
__________________
http://getfirebug.com/
SeattleMicah is offline   Reply With Quote
Old 10-13-2012, 01:45 AM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by SeattleMicah View Post
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']){ 
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Advertisement
Log in to turn off these ads.