GIF89a php
Current File : /home/hencockfreshchic/public_html/admin.cpanel/uploads/updateCat.php
<?php
ob_start();
ini_set('error_reporting', E_STRICT);
include("connect.php");

$cat=str_replace("'","\'",trim($_POST['cat']));
$srr=$_POST['srr'];


// if image gone null
if($_FILES["image"]["name"]=="")
{
	$sql2="UPDATE `category` SET `cat_name`='".$cat."' WHERE `sr`='".$srr."'";
	$rs2=mysqli_query($conn,$sql2);
	if($rs2){
		echo '<script>alert("Category has been updated successfully");</script>';
   echo '<script>window.location.href="addCategory.php";</script>';
	}
	else
	{
		echo '<script>alert("Unable to update category");</script>';
   echo '<script>window.location.href="addCategory.php";</script>';
	}
}
else
{
$temp = explode(".", $_FILES["image"]["name"]);
$target_dir='cat_icon/'.date('Ymdhis').'.'.end($temp);

if (file_exists($target_dir)) {
   echo '<script>alert("File already exist | try another file");</script>';
   echo '<script>window.location.href="addCategory.php";</script>';
}
else
{
	$FileType = strtolower(pathinfo($target_dir,PATHINFO_EXTENSION));
	if($FileType != "png" && $FileType != "jpg" && $FileType != "jpeg" )
{
	// file format not supportedonly images allows
	 echo '<script>alert("Invalid image format");</script>';
 	echo '<script>window.location.href="addCategory.php";</script>';	
}
else
{

	move_uploaded_file($_FILES["image"]["tmp_name"],$target_dir);
$sql="UPDATE `category` SET `cat_name`='".$cat."',`cat_icon`='".$target_dir."' WHERE `sr`='".$srr."'";
$rs=mysqli_query($conn,$sql);
if($rs>0){
echo '<script>alert("Category has been updated successfully"); window.location.href="addCategory.php";</script>';
}else
{
echo '<script>alert("Unable to update category | Contact to developers"); window.location.href="addCategory.php";</script>';
}

}
}
}

?>