Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 21st, 2006, 3:20 PM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Replacing an old image, Editing help.

I am having a little difficulties here, basically this form load the record after the user click on the edit link that exist on another page, the update of the country name and currency works fine, but cant get the image update working, the user will have the option to update the image by replacing it by the new one...

The error i get is:
Notice: Undefined index: uploaded in c:\apache\htdocs\currency\edit.php on line 59
No File Selected or File too Large!

this is my code
<?php
require_once('config.inc.php');
include('session.php');

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) 
	{
	  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
	}

if (isset($_GET['ID'])) 
{
	 	$colname_currency = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
		mysql_select_db( $database, $dbcnx );
		$query_currency = sprintf("SELECT * FROM countries WHERE ID = %s",  $colname_currency);
		$view_currency = mysql_query($query_currency, $dbcnx) or die(mysql_error());
		$row_currency = mysql_fetch_assoc($view_currency);
}

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
	  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
	
	  switch ($theType) 
	  {
	    case "text":
	      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	      break;    
	    case "long":
	    case "int":
	      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
	      break;
	    case "double":
	      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
	      break;
	    case "date":
	      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
	      break;
	    case "defined":
	      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
	      break;
		}
	return $theValue;
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editfrm")) 
{

  $image = $fileName = $_FILES['uploaded']['name'];
  $updateSQL = sprintf("UPDATE countries SET countryname = %s , currency = %s, imgpath = '$image' WHERE ID=%s",
                       GetSQLValueString($_POST['countryname'], "text"),
                       GetSQLValueString($_POST['currency'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));
  mysql_select_db( $database, $dbcnx );
  $Result1 = mysql_query($updateSQL) or die(mysql_error());
  echo "<meta http-equiv=\"refresh\" content=\"0;URL=admin.php\">";
}

if (is_uploaded_file($_FILES['uploaded']['tmp_name'])) 
{
	$fileName = $_FILES['uploaded']['name']; 
	$fileType = $_FILES['uploaded']['type']; 
	if (file_exists($fileName)) 
	{ 
		echo "Duplicate File Found."; 
		include 'form.php'; 
		exit(); 
	} 
		else 
			{ 
			if (($fileType == 'image/jpg') || ($fileType == 'image/pjpeg') || ($fileType == 'image/jpeg') || ($fileType == 'image/gif') || ($fileType == 'image/png') ) 
				{ 
							if (move_uploaded_file($_FILES['uploaded']['tmp_name'],$upload_folder.''.$fileName)) 
							{ 
								//echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=redirect.htm\">";
								exit(); 
							} 
							else 
							{ 
								echo "Unable to upload file: ".$fileName; 
								include 'form.php'; 
								exit(); 
							} 
				} 
			else 
				{ 
					echo $fileType. ": Unknown File Type!"; 
					include 'form.php'; 
					exit(); 
				} 
			} 
} 
else 
	{ 
		echo "No File Selected or File too Large!"; 
		exit(); 
	}
?>
<html>
<head>
<title>Administrator Settings</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<br><br>
<?php include('header.php');?>
<br><br>
<table border="0" style="border-style:solid; border-width:1px; " align=center bordercolor="#000000" cellspacing="1" width="38%">
	<tr>
		<td height="22" align=center class="style6" colspan="2">Edit Current Fild</td>
	</tr>
		<form name="editfrm" action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data">
			<tr>
				<td  align=left height=22 class=style5>&nbsp;Country Name</td>
				<td class=style5><input name="countryname" type="text" id="countryname" value="<?php echo $row_currency['countryname'];?>" size="14"></td>
			</tr>
			<tr>
				<td align=left height=22 class=style5>&nbsp;Currency</td>
				<td class=style5><input name="currency" type="text" id="currency" value="<?php echo $row_currency['currency'];?>" size="14">&nbsp;Enter A Number (eg. 2.30)</td>
			</tr>
			<tr>
				<td align=left height=22 class=style5 rowspan="2">&nbsp;Image</td>
				<td class=style5>&nbsp;Current Image&nbsp;<img src="<?php echo "images/".$row_currency['imgpath']; ?>"></td>
			</tr>
			<tr>
				<td class=style5>&nbsp;New Image&nbsp;<input type=file name="uploaded">
				<input type="hidden" name="MAX_FILE_SIZE" value="1000000"></td>
			</tr>
			<tr>
				<td align=right height=22 class=style6 colspan=2><input type="submit" name="edit" id="edit" value="Edit"></td>
			</tr>
				<input type="hidden" name="ID" value="<?=$_GET['ID'];?>">
				<input type="hidden" name="imgpath" value="<?php echo $row_currency['imgpath'];?>">
				<input type="hidden" name="MM_update" value="editfrm">
			</form>
</table>
<br><br>
</body>
</html>



Thanks in advance.
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC