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

$banner_cat=$_POST['banner_cat'];
$banner_link=$_POST['banner_link'];
$title=$_POST['title'];
$desc=$_POST['desc'];
$offers=$_POST['offers'];
$srr=$_POST['srr'];

//check image is coming or not
if($_FILES["image"]["name"]=="")
{
	// update all fields without image
$sql2="UPDATE `banner_images` SET `banner_name`='".$banner_cat."',`banner_cat`='".$banner_link."',`title`='".$title."',`banner_desc`='".$desc."',`offer_title`='".$offers."' WHERE `sr`='".$srr."'";
$rs2=mysqli_query($conn,$sql2);

if($rs2>0)
{
	 echo '<script>alert("Banner has been updated on website successfully");</script>';
     echo '<script>window.location.href="addbanner.php";</script>';
	// header("Location: cardMe.php?uid=".$uid."");
}
else
{
		 echo '<script>alert("Unable to update banner");</script>';
		echo '<script>window.location.href="addbanner.php";</script>';
}
}
else{
// target directory
$target_dir="prod_image/".mt_rand(100,1000).mt_rand(231,9475).trim($_FILES["image"]["name"]);
//$url="prod_image/".trim($_FILES["image"]["name"]);
//unlike($target_dir);

// Check if file already exists
if (file_exists($target_dir)) {
   echo '<script>alert("Image already exist | try another file");</script>';
   echo '<script>window.location.href="addbanner.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="addbanner.php";</script>';

	
}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"],$target_dir);
	//runQuery($cat,$subcat,$pname,$qty,$rprice,$sprice,$pcode,$mff,$desc,$url);
$sql="INSERT INTO `banner_images`(`banner_name`, `banner_cat`, `banner_image`,`title`,`banner_desc`,`offer_title`) VALUES ('".$banner_cat."','".$banner_link."','".$target_dir."','".$title."','".$desc."','".$offers."')";
$rs=mysqli_query($conn,$sql);

if($rs>0)
{
	 echo '<script>alert("Banner live on website successfully");</script>';
     echo '<script>window.location.href="addbanner.php";</script>';
	// header("Location: cardMe.php?uid=".$uid."");
}
else
{
		 echo '<script>alert("Unable to save banner");</script>';
		echo '<script>window.location.href="addbanner.php";</script>';
}


}
}
}
?>