<?php
$title = "Add new Product";
include("head.php");
$con = connectBD();
$item_name = isset($_POST['item_name'])?$_POST['item_name']:"";
$item_desc = isset($_POST['item_desc'])?$_POST['item_desc']:"";
$price = isset($_POST['price'])?$_POST['price']:"0";
$category_id = isset($_POST['category_id'])?$_POST['category_id']:"0";
$item_price = isset($_POST['item_price'])?$_POST['item_price']:"0";
$item_qty = isset($_POST['item_qty'])?$_POST['item_qty']:"0";
if(isset($_GET['action']) && $_GET['action']=="edit")
{
$id = $_GET['id'];
if(isset($_POST['item_name']) && $_POST['item_name']!="" && $_POST['item_desc']!="" && isset($_FILES['item_img']) && $_FILES['item_img']['size']>0)
{
$imgURL = "../images/" .$_FILES['item_img']['name'];
move_uploaded_file($_FILES['item_img']['tmp_name'], $imgURL);
if(editItem($con, $id , $item_name , $item_desc, $imgURL , $item_price, $category_id, $item_qty ))
echo "<div class='info'>Product updatd successfully.</div>";
else
echo "<div class='info'>Couldn't update this product, please try again later.</div>";
}else{
$sql = "SELECT * FROM `items` where id = ".$id;
$res = mysqli_query($con, $sql);
$row = mysqli_fetch_array($res);
$item_name = $row["name"];
$item_desc = $row["description"];
$item_price = $row["price"];
$category_id = $row["category_id"];
$item_qty = $row["qty"];
if(isset($_FILES['item_img']['size']) && $_FILES['item_img']['size']==0){
echo "<div class='errorbox notice'>You didn't select an image.</div>";
}
?>
التعليقات