PDA

View Full Version : Changing Images on Upload Edit


peakymatt
10-17-2012, 11:28 AM
Good Evening All
This is my first post to this forum. I am quite new to php coding and have got myself totally lost.

I am developing a website for a music company, that want to upload their own product. I have created an upload page which stores all the details in a sql database and uploads an image of the instrument to a folder "ing" to the server. This all works a treat.

A number of the entries have no photo supplied so a generic image has been uploaded in its place, that says "No image".

I have created a page to edit the entries so that the client can make changes to existing product, however I am now totally lost in how to replace the "No Image" image with an image of a new instrument.

Any help you could provide on this would be a great help. I will supply my code for viewing, however I am pretty sure it is a total mess.

Thanks in advance.




<?php require_once('Connections/xxxxxx.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "Administrator";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && false) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "bad_access.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "upload")) {
$updateSQL = sprintf("UPDATE tb_instruments SET sub_category=%s, prod_name=%s, brand=%s, `desc`=%s, colour=%s, price_s=%s, price_r=%s, Category=%s, paypal=%s WHERE prod_ID=%s",


GetSQLValueString($_POST['sub_category'], "text"),
GetSQLValueString($_POST['prod_name'], "text"),
GetSQLValueString($_POST['brand'], "text"),
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['colour'], "text"),
GetSQLValueString($_POST['price_s'], "int"),
GetSQLValueString($_POST['price_r'], "int"),
GetSQLValueString($_POST['Category'], "text"),
GetSQLValueString($_POST['paypal'], "text"),
GetSQLValueString($_POST['prod_ID'], "int"));


mysql_select_db($database_xxxxx, $xxxxx);
$Result1 = mysql_query($updateSQL, $xxxxx) or die(mysql_error());


// function to get file extension
function getExtension($str) {

$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
// define max file size, change to suit your own maximum file size
define ("MAX_SIZE","1000");
$errors=0;
//get the original file from form
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$image = $_FILES["file"]["name"];// from your upload form
$uploadedfile = $_FILES['file']['tmp_name'];// from your upload form
// check for correct file extension
if ($image)
{
$filename = stripslashes($_FILES['file']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo ' Unknown Image extension! ';// build your own error handling here
$errors = 1;
}
// check for correct file size
else
{
$size=filesize($_FILES['file']['tmp_name']);

if ($size > MAX_SIZE*1024)
{
echo "You have exceeded the size limit";// build your own error handling here
$errors = 1;
}
// check which extension we have and create file
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
//resize image and create thumbs and small thumbs
list($width,$height)=getimagesize($uploadedfile);
//for main images, this keeps the width at 300px regardless of portrait or landscape
$newwidth=300;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
//for thumbnails, change the $newwidth variable to what ever size you need
if($width > $height){//landscape
$newwidth1=120;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1) ;
}elseif($width < $height){//portrait
$newheight1=120;
$newwidth1=($width/$height)*$newheight1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1) ;
}
//for smaller thumbnails, my site required this smaller thumb. Delete this section if you dont need it
if($width > $height){//landscape
$newwidth2=50;
$newheight2=($height/$width)*$newwidth2;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2) ;
}elseif($width < $height){//portrait
$newheight2=50;
$newwidth2=($width/$height)*$newheight2;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2) ;
}
// create new resized files
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$ne wheight,$width,$height);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$ newheight1,$width,$height);

imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$ newheight2,$width,$height);
//declare destinations
$filename = "img/". $_FILES['file']['name']; //
$filename1 = "img/thumbs/". $_FILES['file']['name']; // your destination paths here
$filename2 = "img/small/". $_FILES['file']['name']; //
//write files to folders
imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);
imagejpeg($tmp2,$filename2,100);
//destroy temps to save memory
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
imagedestroy($tmp2);
}
}
}
//If no errors registered, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "Image Uploaded Successfully!";
}

$updateGoTo = "instrument_admin_view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_Recordset1 = "-1";
if (isset($_GET['recordID'])) {
$colname_Recordset1 = $_GET['recordID'];
}
mysql_select_db($database_ramos, $ramos);
$query_Recordset1 = sprintf("SELECT * FROM tb_instruments WHERE prod_ID = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $ramos) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin_temp.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="Music Tuition at home, Canberra, gungahlin, tuggeranong, woden, weston creek, queanbeyan, jerrabomberra, Yass, Tumut, captains flat, bungendore, tarago, goulburn, gundagai, tumbarumba, batlow, adelong, brungle, talbingo, one on one lessons, group lessons, string lessons, violin lessons, viola lessons, cello lessons, banjo lessons, flute lessons, saxophone lessons, trumpet lessons, clarinet lessons, guitar lessons, bass guitar lessons, drum lessons, singing lessons, drama classes, woodwind lessons, brass lessons, reeds, instrument sales, intrument accesssories, tuition books, instrument hire" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ramos Music Instrument Upload Page</title>
<!-- InstanceEndEditable -->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

<script type="text/javascript" src="scripts/fadeImages.js"></script>
<link href="css/int-admin.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
body {
background-image: url();
background-repeat: no-repeat;
}
</style>
</head>

<body>

<div class="container">
<div class="sidebar1">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></div>
<div class="content">
<table width="100%" height="215" align="center" cellpadding="0" cellspacing="0" class="nav">
<tr>
<td width="75%" height="213" valign="top"><table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td height="178" valign="top"></tr>
<tr>
<td height="21" align="center" valign="middle"><ul id="MenuBar2" class="MenuBarHorizontal">
<li><a href="Index.htm">Home</a> </li>
<li><a href="Index.html">Log Out</a></li>
<li><a href="contacts.html" class="MenuBarItemSubmenu">Contact</a>
<ul>
<li><a href="map.html" title="See how far we go.">Tutoring Locations</a></li>
</ul>
</li>
</ul></td>
</tr>
</table></td>
<td width="25%" valign="top"><img src="images/ramos Header_admin.jpg" width="389" height="207" /></td>
</tr>
</table>
<!-- InstanceBeginEditable name="Content" -->
<p class="admin_header">Edit Instruments Page</p>
<p class="firstParagraph">Use this form to Edit Instruments to the website for the public to view.</p>
<p class="firstParagraph"><a href="instrument_view_new.php">Click here when you have finished inputting data.</a></p>
<?php









$filePath = $uploadDir . $name;


mysql_select_db($database_ramos, $ramos);
//include 'file:///Macintosh HD/Applications/MAMP/htdocs/library/config.php';
//include 'file:///Macintosh HD/Applications/MAMP/htdocs/library/opendb.php';

if(!get_magic_quotes_gpc())
{
$name = addslashes($name);
$filePath = addslashes($filePath);
}

echo '<p align="center"><img src="images/Anim sax.gif" alt="" height="80" width="auto"></p>';
echo '<p align="center">Thankyou, your File has uploaded successfully.</p>';


?>

<form name="upload" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data">
<table width="478" border="0" align="center" cellpadding="1" cellspacing="1" class="table">
<tr>
<td>ID</td>
<td bgcolor="#CCCCCC"><input name="prod_ID" type="text" id="prod_ID" value="<?php echo $row_Recordset1['prod_ID']; ?>" size="40" /></td>
</tr>
<tr>
<td>Category</td>
<td bgcolor="#CCCCCC"><input name="Category2" type="text" id="Category2" value="<?php echo $row_Recordset1['Category']; ?>" size="40" /></td>
</tr>
<tr>
<td width="154">Sub Category</td>
<td width="315" bgcolor="#CCCCCC"><input name="sub_category" type="text" id="sub_category" value="<?php echo $row_Recordset1['sub_category']; ?>" size="40" /></td>
</tr>
<tr>
<td>Product Name</td>
<td bgcolor="#CCCCCC"><input name="prod_name" type="text" id="prod_name" value="<?php echo $row_Recordset1['prod_name']; ?>" size="40" /></td>
</tr>
<tr>
<td>Brand</td>
<td bgcolor="#CCCCCC"><input name="brand" type="text" id="brand" value="<?php echo $row_Recordset1['brand']; ?>" size="40" /></td>
</tr>
<tr>
<td>Colour</td>
<td bgcolor="#CCCCCC"><input name="colour" type="text" id="colour" value="<?php echo $row_Recordset1['colour']; ?>" size="40" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<td>Regular Price</td>
<td bgcolor="#CCCCCC"><input name="price_r" type="text" id="price_r" value="<?php echo $row_Recordset1['price_r']; ?>" size="40" /></td>
</tr>
<tr>
<td>Sale Price</td>
<td bgcolor="#CCCCCC"><input name="price_s" type="text" id="price_s" value="<?php echo $row_Recordset1['price_s']; ?>" size="40" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<td>Description</td>
<td bgcolor="#CCCCCC"><textarea name="desc" id="desc" cols="40" rows="5"><?php echo $row_Recordset1['desc']; ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<td>Paypal &quot;Add to Cart&quot; Code. This is copied stright from PayPal.</td>
<td bgcolor="#CCCCCC"><textarea name="paypal" id="paypal" cols="40" rows="5"><?php echo $row_Recordset1['paypal']; ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
<tr>
<td>Select Image</td>
<td bgcolor="#CCCCCC"><input name="file" type="file" id="file" value="<?php echo $row_Recordset1['img_loc']; ?>" />
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><span class="shopheader_categorytree"><strong>Note:</strong> When uploading an image please make sure that it has been resized to a max of 900px wide.</span></td>
</tr>
<tr>
<td><input name="upload" type="submit" class="button" id="upload" value=" Upload " /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p><br />
</p>
<input type="hidden" name="MM_update" value="form" />
<input type="hidden" name="MM_update" value="upload" />
</form>
<br /><!-- InstanceEndEditable -->
<p><br />
</p>
</div>
<div class="sidebar2">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<div class="footer">
<p>.</p>
<!-- end .footer --></div>
<!-- end .container --></div>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar2", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($Recordset1);
?>

edbr
10-18-2012, 01:08 AM
I cant see wht makes the No image dsplay so ill have to make some guesses.
no image will show if img_loc' is null or =" ",
you will need to make an upload script (and form) just for that field and use an update statement and a where clause to make sure it is the correct record you are updating, this is usually on the id

peakymatt
10-18-2012, 06:27 AM
Hi Edbr, thanks for the response.

The "No Image" is a graphic that is loaded in the initial upload form that is chosen when there is no instrument picture available.

So therefore is what you are saying this: That I need to have one update script and form for the instrument details, then another form and script to update or replace the image??

Thanks again for your help

edbr
10-18-2012, 06:49 AM
yes thats my guess, if you add an image later you will have to update that field with the image location

peakymatt
10-18-2012, 07:56 AM
Ok, didn't really want to update the one database record twice, but thanks for your help

peakymatt
10-18-2012, 10:45 AM
OK

I have now created a page with an update form for the database record that holds all details of the instruments. This works and updates. Under that form is another form for the image upload, with a separate upload button once they select their image. It uploads the image to the server and puts it in the img folder however doesn't write to the database.

Not sure why, also not sure how to link it to the database record in the form that updates the record.

Please help.

Thanks, code attached

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

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

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE tb_instruments SET sub_category=%s, prod_name=%s, brand=%s, `desc`=%s, colour=%s, price_s=%s, price_r=%s, img_loc=%s, Category=%s, paypal=%s WHERE prod_ID=%s",
GetSQLValueString($_POST['sub_category'], "text"),
GetSQLValueString($_POST['prod_name'], "text"),
GetSQLValueString($_POST['brand'], "text"),
GetSQLValueString($_POST['desc'], "text"),
GetSQLValueString($_POST['colour'], "text"),
GetSQLValueString($_POST['price_s'], "int"),
GetSQLValueString($_POST['price_r'], "int"),
GetSQLValueString($_POST['img_loc'], "text"),
GetSQLValueString($_POST['Category'], "text"),
GetSQLValueString($_POST['paypal'], "text"),
GetSQLValueString($_POST['prod_ID'], "int"));

mysql_select_db($database_ramos, $ramos);
$Result1 = mysql_query($updateSQL, $ramos) or die(mysql_error());

$updateGoTo = "instrument_admin_view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_inst_update = "-1";
if (isset($_GET['recordID'])) {
$colname_inst_update = $_GET['recordID'];
}
mysql_select_db($database_ramos, $ramos);
$query_inst_update = sprintf("SELECT * FROM tb_instruments WHERE prod_ID = %s", GetSQLValueString($colname_inst_update, "int"));
$inst_update = mysql_query($query_inst_update, $ramos) or die(mysql_error());
$row_inst_update = mysql_fetch_assoc($inst_update);
$totalRows_inst_update = mysql_num_rows($inst_update);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin_temp.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="Music Tuition at home, Canberra, gungahlin, tuggeranong, woden, weston creek, queanbeyan, jerrabomberra, Yass, Tumut, captains flat, bungendore, tarago, goulburn, gundagai, tumbarumba, batlow, adelong, brungle, talbingo, one on one lessons, group lessons, string lessons, violin lessons, viola lessons, cello lessons, banjo lessons, flute lessons, saxophone lessons, trumpet lessons, clarinet lessons, guitar lessons, bass guitar lessons, drum lessons, singing lessons, drama classes, woodwind lessons, brass lessons, reeds, instrument sales, intrument accesssories, tuition books, instrument hire" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Welcome to Ramos Music</title>
<!-- InstanceEndEditable -->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>

<script type="text/javascript" src="scripts/fadeImages.js"></script>
<link href="css/int-admin.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
body {
background-image: url();
background-repeat: no-repeat;
}
</style>
</head>

<body>

<div class="container">
<div class="sidebar1">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></div>
<div class="content">
<table width="100%" height="215" align="center" cellpadding="0" cellspacing="0" class="nav">
<tr>
<td width="75%" height="213" valign="top"><table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td height="178" valign="top"></tr>
<tr>
<td height="21" align="center" valign="middle"><ul id="MenuBar2" class="MenuBarHorizontal">
<li><a href="Index.htm">Home</a> </li>
<li><a href="Index.html">Log Out</a></li>
<li><a href="contacts.html" class="MenuBarItemSubmenu">Contact</a>
<ul>
<li><a href="map.html" title="See how far we go.">Tutoring Locations</a></li>
</ul>
</li>
</ul></td>
</tr>
</table></td>
<td width="25%" valign="top"><img src="images/ramos Header_admin.jpg" width="389" height="207" /></td>
</tr>
</table>
<!-- InstanceBeginEditable name="Content" -->
<p>Instrument Update Page</p>
<p>This page is used to update the Instruments for Ramos Music.</p>
<form id="form1" name="form1" method="post" action="">
</form>
<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Product ID</td>
<td><?php echo $row_inst_update['prod_ID']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Category:</td>
<td><input type="text" name="Category" value="<?php echo htmlentities($row_inst_update['Category'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sub Category:</td>
<td><input type="text" name="sub_category" value="<?php echo htmlentities($row_inst_update['sub_category'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Product Name:</td>
<td><input type="text" name="prod_name" value="<?php echo htmlentities($row_inst_update['prod_name'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Brand:</td>
<td><input type="text" name="brand" value="<?php echo htmlentities($row_inst_update['brand'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Description:</td>
<td><input type="text" name="desc" value="<?php echo htmlentities($row_inst_update['desc'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Colour:</td>
<td><input type="text" name="colour" value="<?php echo htmlentities($row_inst_update['colour'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Sale Price:</td>
<td><input type="text" name="price_s" value="<?php echo htmlentities($row_inst_update['price_s'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Regular Price:</td>
<td><input type="text" name="price_r" value="<?php echo htmlentities($row_inst_update['price_r'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Paypal:</td>
<td><input type="text" name="paypal" value="<?php echo htmlentities($row_inst_update['paypal'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Current Image:</td>
<td><img src="img/thumbs/<?php echo $row_inst_update['img_loc']; ?>" alt="" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Update record" /></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form2" />
<input type="hidden" name="prod_ID" value="<?php echo $row_inst_update['prod_ID']; ?>" />
</form>
<p>&nbsp;</p>
<p><?php



// function to get file extension
function getExtension($str) {

$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
// define max file size, change to suit your own maximum file size
define ("MAX_SIZE","1000");
$errors=0;
//get the original file from form
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$image = $_FILES["file"]["name"];// from your upload form
$uploadedfile = $_FILES['file']['tmp_name'];// from your upload form
// check for correct file extension
if ($image)
{
$filename = stripslashes($_FILES['file']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo ' Unknown Image extension! ';// build your own error handling here
$errors = 1;
}
// check for correct file size
else
{
$size=filesize($_FILES['file']['tmp_name']);

if ($size > MAX_SIZE*1024)
{
echo "You have exceeded the size limit";// build your own error handling here
$errors = 1;
}
// check which extension we have and create file
if($extension=="jpg" || $extension=="jpeg" )
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png")
{
$uploadedfile = $_FILES['file']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
else
{
$src = imagecreatefromgif($uploadedfile);
}
//resize image and create thumbs and small thumbs
list($width,$height)=getimagesize($uploadedfile);
//for main images, this keeps the width at 300px regardless of portrait or landscape
$newwidth=300;
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
//for thumbnails, change the $newwidth variable to what ever size you need
if($width > $height){//landscape
$newwidth1=120;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1) ;
}elseif($width < $height){//portrait
$newheight1=120;
$newwidth1=($width/$height)*$newheight1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1) ;
}
//for smaller thumbnails, my site required this smaller thumb. Delete this section if you dont need it
if($width > $height){//landscape
$newwidth2=50;
$newheight2=($height/$width)*$newwidth2;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2) ;
}elseif($width < $height){//portrait
$newheight2=50;
$newwidth2=($width/$height)*$newheight2;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2) ;
}
// create new resized files
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$ne wheight,$width,$height);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$ newheight1,$width,$height);

imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$ newheight2,$width,$height);
//declare destinations
$filename = "img/". $_FILES['file']['name']; //
$filename1 = "img/thumbs/". $_FILES['file']['name']; // your destination paths here
$filename2 = "img/small/". $_FILES['file']['name']; //
//write files to folders
imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);
imagejpeg($tmp2,$filename2,100);
//destroy temps to save memory
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
imagedestroy($tmp2);
}
}
}
//If no errors registered, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo "Image Uploaded Successfully!";
}



//$uploadDir = 'img/';

if(isset($_POST['upload']))
{
$fileName = $_FILES['file']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$img_name = $_POST['img_name'];


$filePath = $uploadDir . $name;

//$result = move_uploaded_file($name, $filePath);
//if (!$result) {
//echo "Error uploading file";
//exit;
//}

mysql_select_db($database_ramos, $ramos);
//include 'file:///Macintosh HD/Applications/MAMP/htdocs/library/config.php';
//include 'file:///Macintosh HD/Applications/MAMP/htdocs/library/opendb.php';

if(!get_magic_quotes_gpc())
{
$name = addslashes($name);
$filePath = addslashes($filePath);
}

$query = "INSERT INTO tb_instruments ( filetype, size, type, name_loc, img_loc, name ) ".
"VALUES ('$filetype', '$fileSize', '$fileType', '$img_name', '$fileName', '$filePath')";

mysql_query($query) or die('Error, query failed : ' . mysql_error());

//include 'file:///Macintosh HD/Applications/MAMP/htdocs/library/closedb.php';
echo '<p align="center"><img src="images/Anim sax.gif" alt="" height="80" width="auto"></p>';
echo '<p align="center">Thankyou, your File has uploaded successfully.</p>';

}
?>

Please fill in form below to upload your New Instrument Image.<form name="upload" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data">
<table width="367" border="0" align="center" cellpadding="1" cellspacing="1" class="table">
<tr>
<td width="154">Select Image</td>
<td width="315" bgcolor="#CCCCCC"><input name="file" type="file" id="file" /></td>
</tr>
<tr>
<td><input type="hidden" name="MAX_FILE_SIZE" value="2000000" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="upload2" type="submit" class="button" id="upload" value="Upload Image" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<p><br />
</p>
<input type="hidden" name="MM_update" value="form" />
</form></p>
<p>&nbsp;</p>