Jump to content

Update erased almost everything! :S


mike12255

Recommended Posts

So im designing a small kind of CMS for a client and i have a function created so they can modify a current product, but if they upload a new image the new image has to be resized and what not, so im trying to check for that and if that needs done, do it then update the database with the information, but if it dosn't need done, then leave it and update all the other information. However it seems my statment cleared everything in the row except for th_name any ideas??

 

<?php
include ("connect.php"); 
if(isset($_GET['id']) && !is_numeric($_GET['id'])){
   die('Forbidden');
   }
$id = (int) $_GET['id'];

$sql = "SELECT *  FROM tbl_product WHERE pd_id = $id";

$result = mysql_query($sql) or die (mysql_error());
$row =  mysql_fetch_array($result);
extract($row);
?>

<html>
<head>
<title>Kaon Furniture Canada!</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333333;
}
body {
background-color: #FFFFFF;
background-image: url(background.gif);
background-repeat: repeat-x;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onLoad="MM_preloadImages('images/rollover_03.gif','images/rollover_04.gif','images/rollover_05.gif','images/rollover_06.gif','images/rollover_07.gif')">
<!-- ImageReady Slices (index.psd) -->
<table width="800" height="570" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
	<td colspan="9">
		<img src="images/index_01.gif" width="800" height="13" alt=""></td>
</tr>
<tr>
	<td rowspan="4">
		<img src="images/index_02.gif" width="11" height="142" alt=""></td>
	<td colspan="2"><a href="index.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image19','','images/rollover_03.gif',1)"><img src="images/index_03.gif" name="Image19" width="155" height="38" border="0"></a></td>
  <td colspan="2"><a href="aboutus.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image20','','images/rollover_04.gif',1)"><img src="images/index_04.gif" name="Image20" width="156" height="38" border="0"></a></td>
  <td><a href="products.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image21','','images/rollover_05.gif',1)"><img src="images/index_05.gif" name="Image21" width="155" height="38" border="0"></a></td>
  <td><a href="pictures.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image22','','images/rollover_06.gif',1)"><img src="images/index_06.gif" name="Image22" width="156" height="38" border="0"></a></td>
  <td><a href="contactus.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image23','','images/rollover_07.gif',1)"><img src="images/index_07.gif" name="Image23" width="155" height="38" border="0"></a></td>
<td rowspan="4">
		<img src="images/index_08.gif" width="12" height="142" alt=""></td>
</tr>
<tr>
	<td colspan="7">
		<img src="images/index_09.gif" width="777" height="18" alt=""></td>
</tr>
<tr><?php




if(isset($_POST['submit'])){
$id =$_GET['id'];
$path = $_POST['file'];
$cat = $_POST['catagory'];
$desc = $_POST['desc'];
$name =$_POST['name'];

$sql = "SELECT *  FROM tbl_product WHERE pd_id = $id";

$result = mysql_query($sql) or die (mysql_error());
$row =  mysql_fetch_array($result);
extract($row);


if ($path != $pd_path){

   $idir = "images/";   // Path To Images Directory
$tdir = "images/thumbs/";   // Path To Thumbnails Directory
$twidth = "125";   // Maximum Width For Thumbnail Images
$theight = "84";   // Maximum Height For Thumbnail Images

 $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use
  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
    $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']);   // Move Image From Temporary Location To Permanent Location 
$path = "$idir" . $_FILES['imagefile']['name'];
$name = $_POST['name'];
$desc = $_POST['desc'];
$area = $_POST['catagory'];
    $thpath = "$tdir" . $_FILES['imagefile']['name'];
	$query = "UPDATE tbl_product SET pd_name = '$name', pd_path = '$path', pd_desc = '$desc', cat_name = '$cat_name', th_path = '$thpath' WHERE pd_id = $id";
mysql_query($query) or die (mysql_error());
    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location
     // print 'Image uploaded successfully.<br />';   // Was Able To Successfully Upload Image
      $simg = imagecreatefromjpeg("$idir" . $url);   // Make A New Temporary Image To Create The Thumbanil From
      $currwidth = imagesx($simg);   // Current Image Width
      $currheight = imagesy($simg);   // Current Image Height
      if ($currheight > $currwidth) {   // If Height Is Greater Than Width
         $zoom = $twidth / $currheight;   // Length Ratio For Width
         $newheight = 100;   // Height Is Equal To Max Height
         $newwidth = 150;   // Creates The New Width
      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
        $zoom = $twidth / $currwidth;   // Length Ratio For Height
        $newwidth = 150;   // Width Is Equal To Max Width
        $newheight = 100;   // Creates The New Height
      }
      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
      $palsize = ImageColorsTotal($simg);
      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
      }
      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
      imagejpeg($dimg, "$tdir" . $url);   // Saving The Image
      imagedestroy($simg);   // Destroying The Temporary Image
      imagedestroy($dimg);   // Destroying The Other Temporary Image
     header ("Location: productlist.php");
    } else {
      print '<font color="#FF0000">ERROR: Unable to upload image.</font>';   // Error Message If Upload Failed
    }
  } else {
    print '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';   // Error Message If Filetype Is Wrong
    print $file_ext;   // Show The Invalid File's Extention
    print '.</font>';
  } 
  }

}else{

$query = "UPDATE tbl_product SET pd_name = '$name', pd_path = '$path', pd_desc = '$desc', cat_name = '$cat_name' WHERE pd_id = $id";
mysql_query($query) or die (mysql_error());
header("Location: productlist.php");
}



?>
	<td rowspan="2">
		<img src="images/index_10.gif" width="7" height="86" alt=""></td>
	<td colspan="2">
		<img src="images/index_11.gif" width="152" height="62" alt=""></td>
	<td colspan="4" rowspan="2">
		<img src="images/index_12.gif" width="618" height="86" alt=""></td>
</tr>
<tr>
	<td colspan="2">
		<img src="images/index_13.gif" width="152" height="24" alt=""></td>
</tr>
<tr>
	<td height="400" colspan="9" valign="top" background="images/index_14.gif"><blockquote>
	  <table width="366" height="339" border="0">
	    <tr>
	      <td><table width="480" border="0">
	        <tr>
	          <td>Name:</td>
            </tr>
	        <tr>
	          <td><form name="form1" enctype="multipart/form-data" method="post" action="modify.php?id=<?=$id?>">
	            <label>
	              <input type="text" name="name" id="name" value = "<?=$pd_name?>">
	              </label>
	            </form></td>
            </tr>
	        <tr>
	          <td>Description:</td>
            </tr>
	        <tr>
	          <td><label>
	            <textarea name="desc" id="desc" cols="45" rows="5" ><?=$pd_desc?></textarea>
	            </label>
	            </form></td>
            </tr>
	        <tr>
	          <td>Catagory:</td>
            </tr>
	        <tr>
	          <td><select name="catagory" id="catagory" value = "<?= $cat_name?>">
	            <option>Sofas</option>
	            <option>Beds and Bunks</option>
	            <option>Dressers and Cabinets</option>
	            <option>Side Tables and Desks</option>
	            </select>
	             </td>
            </tr>
	        <tr>
	          <td>Picture:</td>
            </tr>
	        <tr>
	          <td><img src="<?=$th_path?>" alt=""></td>
            </tr>
	        <tr>
	          <td> 
	            <label>
	              <input type="file" name="file" id="file" value="$pd_path">
	              </label>
              </form></td>
            </tr>
	        <tr>
	          <td><label>
	            <input type="submit" name="submit" id="submit" value="Submit">
	            </label>
	            </form></td>
            </tr>
	        </table>
              <?php


?></td>
        </tr>
      </table>
	  <p> </p>
	  <p> </p>
	</blockquote>
	  <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <blockquote>
      <p> </p>
      </blockquote>
    <p> </p>
    <p> </p></td>
</tr>
<tr>
	<td colspan="9">
		<img src="images/index_15.gif" width="800" height="78" alt=""></td>
</tr>
<tr>
	<td>
		<img src="images/spacer.gif" width="11" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="7" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="148" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="4" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="152" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="155" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="156" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="155" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="12" height="1" alt=""></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/150935-update-erased-almost-everything-s/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.