$product_name1 = $_REQUEST['product_name'];
$price1 = $_REQUEST['price'];
$image_name1 = $_REQUEST['image_name'];
$description1 = $_REQUEST['description'];
if ($_FILES["image_path"]["error"] > 0) {
    echo "<font size = '5'><font color=\"#e31919\">Error: NO CHOSEN FILE <br />";
    echo "<p><font size = '5'><font color=\"#e31919\">INSERT TO DATABASE FAILED";
} else {
    $uploaddir = "images/";
    move_uploaded_file($_FILES["image_path"]["tmp_name"], "{$uploaddir}" . $_FILES["image_path"]["name"]);
    echo "<font size = '5'><font color=\"#0CF44A\">SAVED<br>";
}
$file1 = "{$uploaddir}" . $_FILES["image_path"]["name"];
switch ($_REQUEST['operation']) {
    case "add":
        $product->add_product("product_details", "product_name,price,image_name,image_path,description", "'{$product_name}','{$price}','{$image_name}','{$file}','{$description}'");
        break;
    case "update":
        $product->update_product("product_details", "product_name='{$product_name1}',price='{$price1}',image_name='{$image_name1}',image_path='{$file1}',description='{$description1}'", "product_id='{$product_id1}'");
        break;
    case "delete_rec":
        $product->delete_product("product_details", "product_id='{$product_id}'");
        break;
    case "view":
        $product->view_product($product_list, $table);
        break;
    case "view_single":
        $product->view_single_product($product_list, $table, $condition);
        break;
    default:
        echo "<H3 color='red'>Invalid Option Please Try again!</h3>";
Example #2
0
            }
            $product->update_product();
            header('location:index.php?productskjjknjkn=' . $product->product_id);
        }
    }
}
if (isset($_POST['product_name'])) {
    if ($product->product_image == '') {
        $rand = round(rand() * 10000, 4);
        $product->product_image = preg_replace('/[^a-zA-Z0-9\']/', '_', $_POST['product_name']) . $rand;
        $product->product_image = "images/product/" . $product->product_image . '.jpg';
    }
    if (isset($_FILES['product_image_new']) && $_FILES['product_image_new']['name'] != '' && $_FILES["product_image_new"]["type"] == "image/jpeg") {
        move_uploaded_file($_FILES["product_image_new"]["tmp_name"], '../' . $product->product_image);
    }
    $product->product_id = $product->add_product();
    header('location:index.php?products=' . $product->product_id);
}
?>

<?php 
$collection = new Product();
$collection = $collection->getCollection();
foreach ($collection as $product) {
    ?>
<div width="200" style="display: block;width:100%; height:100px ">
<a href="index.php?products=<?php 
    echo $product->product_id;
    ?>
">
<img src="../<?php