www.webdeveloper.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38

Thread: [RESOLVED] PHP Confirm on Delete Confusion

  1. #16
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    Let me know if you want any other files.

  2. #17
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    As you know, as it stands that file doesn't include the confirmation page, so I've made that change. I've commented out all the unused variables and includes. Look for //bionoid where I've made changes:

    With the $product variable, I'm guessing you normally have a foreach($products as $product) that should be in there??

    index.php
    PHP Code:
    <?php

    //require('../model/database.php');
    //require('../model/product_db.php');
    //require('../model/category_db.php');

    function delete_product() {} //bionoid

    if (isset($_POST['action'])) {
        
    $action $_POST['action'];
    } else if (isset(
    $_GET['action'])) {
        
    $action $_GET['action'];
    } else {
        
    $action 'list_products';
    }

    if (
    $action == 'list_products') {
        
    //the below commented area is an error
        // Get the current category ID
        /*$category_id = $_GET['category_id'];
        if (!isset($category_id)) {
            $category_id = 1;
        }*/
        //the below is the corrected version of the above
        
    if ( isset($_GET['category_id']) )
        { 
    $category_id $_GET['category_id']; }
        else
        { 
    $category_id 1; }

        
    // Get product and category data
    //    $category_name = get_category_name($category_id);
    //    $categories = get_categories();
    //    $products = get_products_by_category($category_id);

        
    $product = array('productID' => 1'categoryID' => 99); //bionoid

    /*
    //below is the code to confirm a delete or deny a delete
        // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        // Delete the product
        delete_product($product_id);
        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");

    } else if ($action == 'NO') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
    */


        /*
     // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Delete the product
        delete_product($product_id);

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
        */

    //Display the Product List page for the current category
    //header("Location: product_list.php?category_id=$category_id");


     // Display the product list
        
    include('product_list.php');

    } else if (
    $action == 'delete_product') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];

        include(
    'confirm.php'); //bionoid

        // Delete the product
        //delete_product($product_id);

        // Display the Product List page for the current category
        //header("Location: .?category_id=$category_id");


    //------------

    //bionoid
    } else if ($action == 'YES') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];
        
    // Delete the product
        
    delete_product($product_id);
        
    // Display the Product List page for the current category
        
    header("Location: .?category_id=$category_id");

    } else if (
    $action == 'show_add_form') {
    //    $categories = get_categories();
        
    include('product_add.php');
    } else if (
    $action == 'add_product') {
        
    $category_id $_POST['category_id'];
        
    $code $_POST['code'];
        
    $name $_POST['name'];
        
    $price $_POST['price'];

        
    // Validate the inputs
        
    if (empty($code)) {
            
    $error "The code field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $name))  {
            
    $error "The name field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $price)) {
            
    $error "The price field cannot be blank or be a zero.";
            include(
    '../errors/error.php');
        } else if (!
    is_numeric($price))  {
            
    $error 'The price field must be a valid number.';
            include(
    '../errors/error.php');
        } else if (
    $price <= 0) {
            
    $error 'The price field must be greater than zero.';
            include(
    '../errors/error.php');
        } else {
            
    add_product($category_id$code$name$price);

            
    // Display the Product List page for the current category
            
    header("Location: .?category_id=$category_id");
        }

    }
    ?>
    Also the confirm page isn't able to see the product information when it's being included, but it can see the ones you created from the POST information:

    confirm.php
    PHP Code:
    <form action="." method="post">
        <input type="hidden" name="action" value="YES" />
        <input type="hidden" name="product_id" value="<?php echo $product_id?>" />
        <input type="hidden" name="category_id" value="<?php echo $category_id?>" />
        <input type="submit" value="YES" />
    </form>
    JavaScript: Learn | Validate | Compact

  3. #18
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    My foreach loops are in the product_list.php . . . here is the whole page (including all notes)

    PHP Code:
    <?php include '../view/header.php'?>
    <div id="main">
        <h1>Product List</h1>

        <div id="sidebar">
            <!-- display a list of categories -->
                    <p>&nbsp;</p>
            <h2>Categories</h2>
                    <p>&nbsp;</p>
            <ul>
            <?php foreach ($categories as $category) : ?>
                <li>
                <p class="category"><a href="?category_id=<?php echo $category['categoryID']; ?>">
                    <?php echo $category['categoryName']; ?>
                </a></p>
                </li>
            <?php endforeach; ?>
            </ul>
        </div>

        <div id="content">
            <!-- display a table of products -->
                    <p>&nbsp;</p>
            <h2><?php echo $category_name?></h2>
                    <p>&nbsp;</p>
           <p class="category2"> 
    <!-- 
    <script type='text/javascript'>
    function confirmDelete()
    {
       return confirm("Are you sure you want to delete this?");
    }
    </script>  THIS SCRIPT FUNCTIONS!!! WITH THIS CODE IN WITH THE SUBMIT BUTTON onclick='return confirmDelete()' // -->
    <!-- 
    <script>
    function deleletconfig(){

    var del=confirm("Are you sure you want to delete this record?");
    if (del==true){
    alert ("Record Deleted")
    }else{
    alert("Record Not Deleted")
    }
    return del;
    }
    </script>  THIS SCRIPT FUNCTIONS!!! WITH THIS CODE IN WITH THE SUBMIT BUTTON onclick="return deleletconfig()" // -->

           <table>
                <tr>
                    <th>Code</th>
                    <th>Name</th>
                    <th class="right">Price</th>
                    <th>&nbsp;</th>
                </tr>
                <?php foreach ($products as $product) : ?>
                <tr>
                    <td><?php echo $product['productCode']; ?></td>
                    <td><?php echo $product['productName']; ?></td>
                    <td class="right"><?php echo $product['listPrice']; ?></td>
                    <td>
                    <form action="." method="post">
                        <input type="hidden" name="action"
                               value="delete_product" />                
                        <input type="hidden" name="product_id"
                               value="<?php echo $product['productID']; ?>" />
                        <input type="hidden" name="category_id"
                               value="<?php echo $product['categoryID']; ?>" />
                        <input type="submit" value="Delete"     />
                    </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            </table> 
            </p>
                            <p>&nbsp;</p>
            <p><a href="?action=show_add_form">Add Product</a></p>
                            <p>&nbsp;</p>
                                            <p>&nbsp;</p>
        </div>

    </div>
    <?php include '../view/footer.php'?>
    I'll take a look at what you have posted and get back to you.

  4. #19
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    In light of the full product_list.php file:

    index.php
    PHP Code:
    <?php

    //require('../model/database.php');
    //require('../model/product_db.php');
    //require('../model/category_db.php');

    //bionoid : MY DUMMY FUNCTIONS
    function delete_product() {}
    function 
    get_category_name($id)
    {
        return 
    'CATEGORY_NAME_' $id;
    }
    function 
    get_categories()
    {
        return array(
            array(
    'categoryName' => 'Guitars''categoryID' => 2)
        );
    }
    function 
    get_products_by_category()
    {
        return array(
            array(
    'productCode' => '123''productName' => 'Product 1''listPrice' => '$1''productID' => '99''categoryID' => 2),
            array(
    'productCode' => '456''productName' => 'Product 2''listPrice' => '$2''productID' => '45''categoryID' => 6)
        );
    }


    if (isset(
    $_POST['action'])) {
        
    $action $_POST['action'];
    } else if (isset(
    $_GET['action'])) {
        
    $action $_GET['action'];
    } else {
        
    $action 'list_products';
    }

    if (
    $action == 'list_products') {
        
    //the below commented area is an error
        // Get the current category ID
        /*$category_id = $_GET['category_id'];
        if (!isset($category_id)) {
            $category_id = 1;
        }*/
        //the below is the corrected version of the above
        
    if ( isset($_GET['category_id']) )
        { 
    $category_id $_GET['category_id']; }
        else
        { 
    $category_id 1; }

        
    // Get product and category data
        
    $category_name get_category_name($category_id);
        
    $categories get_categories();
        
    $products get_products_by_category($category_id);

    /*
    //below is the code to confirm a delete or deny a delete
        // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        // Delete the product
        delete_product($product_id);
        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");

    } else if ($action == 'NO') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
    */


        /*
     // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Delete the product
        delete_product($product_id);

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
        */

    //Display the Product List page for the current category
    //header("Location: product_list.php?category_id=$category_id");


     // Display the product list
        
    include('product_list.php');

    } else if (
    $action == 'delete_product') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];

        include(
    'confirm.php'); //bionoid

        // Delete the product
        //delete_product($product_id);

        // Display the Product List page for the current category
        //header("Location: .?category_id=$category_id");


    //------------

    //bionoid
    } else if ($action == 'YES') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];
        
    // Delete the product
        
    delete_product($product_id);
        
    // Display the Product List page for the current category
        
    header("Location: .?category_id=$category_id");

    } else if (
    $action == 'show_add_form') {
    //    $categories = get_categories();
        
    include('product_add.php');
    } else if (
    $action == 'add_product') {
        
    $category_id $_POST['category_id'];
        
    $code $_POST['code'];
        
    $name $_POST['name'];
        
    $price $_POST['price'];

        
    // Validate the inputs
        
    if (empty($code)) {
            
    $error "The code field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $name))  {
            
    $error "The name field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $price)) {
            
    $error "The price field cannot be blank or be a zero.";
            include(
    '../errors/error.php');
        } else if (!
    is_numeric($price))  {
            
    $error 'The price field must be a valid number.';
            include(
    '../errors/error.php');
        } else if (
    $price <= 0) {
            
    $error 'The price field must be greater than zero.';
            include(
    '../errors/error.php');
        } else {
            
    add_product($category_id$code$name$price);

            
    // Display the Product List page for the current category
            
    header("Location: .?category_id=$category_id");
        }

    }
    ?>
    confirm.php
    PHP Code:
    <form action="." method="post">
        <input type="hidden" name="action" value="YES" />
        <input type="hidden" name="product_id" value="<?php echo $product_id?>" />
        <input type="hidden" name="category_id" value="<?php echo $category_id?>" />
        <input type="submit" value="YES" />
    </form>
    JavaScript: Learn | Validate | Compact

  5. #20
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    I've tried this before and received an error (along with the same confirm.php that you have provided)


    PHP Code:
     // Display the product list
        
    include('product_list.php');

    } else if (
    $action == 'delete_product') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];

        include(
    'confirm.php'); //bionoid

    //------------

    //bionoid
    } else if ($action == 'YES') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];
        
    // Delete the product
        
    delete_product($product_id);
        
    // Display the Product List page for the current category
        
    header("Location: .?category_id=$category_id"); 
    I went ahead and copy/pasted your code exactly and uploaded it.

    This is what I get : Fatal error: Cannot redeclare delete_product() in . . . /product_list.php on line 8

    I put both


    PHP Code:
    function delete_product() {} //bionoid 
    and

    PHP Code:
    function delete_product($product_id) {
        global 
    $db;
        
    $query "DELETE FROM products
                  WHERE productID = '
    $product_id'";
        
    $db->exec($query);

    on that line and received the same results. I might be missing something, or my server doesn't like me.

  6. #21
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    Reading your new post, will be back.

  7. #22
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    If you upload "as-is", then comment out all my dummy functions and re-include your php files (they are only to cater for a lacking database):

    index.php
    PHP Code:
    <?php

    require('../model/database.php');
    require(
    '../model/product_db.php');
    require(
    '../model/category_db.php');

    /*
    //bionoid : MY DUMMY FUNCTIONS
    function delete_product() {}
    function get_category_name($id)
    {
        return 'CATEGORY_NAME_' . $id;
    }
    function get_categories()
    {
        return array(
            array('categoryName' => 'Guitars', 'categoryID' => 2)
        );
    }
    function get_products_by_category()
    {
        return array(
            array('productCode' => '123', 'productName' => 'Product 1', 'listPrice' => '$1', 'productID' => '99', 'categoryID' => 2),
            array('productCode' => '456', 'productName' => 'Product 2', 'listPrice' => '$2', 'productID' => '45', 'categoryID' => 6)
        );
    }
    */

    if (isset($_POST['action'])) {
        
    $action $_POST['action'];
    } else if (isset(
    $_GET['action'])) {
        
    $action $_GET['action'];
    } else {
        
    $action 'list_products';
    }

    if (
    $action == 'list_products') {
        
    //the below commented area is an error
        // Get the current category ID
        /*$category_id = $_GET['category_id'];
        if (!isset($category_id)) {
            $category_id = 1;
        }*/
        //the below is the corrected version of the above
        
    if ( isset($_GET['category_id']) )
        { 
    $category_id $_GET['category_id']; }
        else
        { 
    $category_id 1; }

        
    // Get product and category data
        
    $category_name get_category_name($category_id);
        
    $categories get_categories();
        
    $products get_products_by_category($category_id);

    /*
    //below is the code to confirm a delete or deny a delete
        // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        // Delete the product
        delete_product($product_id);
        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");

    } else if ($action == 'NO') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
    */


        /*
     // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Delete the product
        delete_product($product_id);

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
        */

    //Display the Product List page for the current category
    //header("Location: product_list.php?category_id=$category_id");


     // Display the product list
        
    include('product_list.php');

    } else if (
    $action == 'delete_product') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];

        include(
    'confirm.php'); //bionoid

        // Delete the product
        //delete_product($product_id);

        // Display the Product List page for the current category
        //header("Location: .?category_id=$category_id");


    //------------

    //bionoid
    } else if ($action == 'YES') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];
        
    // Delete the product
        
    delete_product($product_id);
        
    // Display the Product List page for the current category
        
    header("Location: .?category_id=$category_id");

    } else if (
    $action == 'show_add_form') {
    //    $categories = get_categories();
        
    include('product_add.php');
    } else if (
    $action == 'add_product') {
        
    $category_id $_POST['category_id'];
        
    $code $_POST['code'];
        
    $name $_POST['name'];
        
    $price $_POST['price'];

        
    // Validate the inputs
        
    if (empty($code)) {
            
    $error "The code field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $name))  {
            
    $error "The name field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $price)) {
            
    $error "The price field cannot be blank or be a zero.";
            include(
    '../errors/error.php');
        } else if (!
    is_numeric($price))  {
            
    $error 'The price field must be a valid number.';
            include(
    '../errors/error.php');
        } else if (
    $price <= 0) {
            
    $error 'The price field must be greater than zero.';
            include(
    '../errors/error.php');
        } else {
            
    add_product($category_id$code$name$price);

            
    // Display the Product List page for the current category
            
    header("Location: .?category_id=$category_id");
        }

    }
    ?>
    confirm.php
    PHP Code:
    <form action="." method="post">
        <input type="hidden" name="action" value="YES" />
        <input type="hidden" name="product_id" value="<?php echo $product_id?>" />
        <input type="hidden" name="category_id" value="<?php echo $category_id?>" />
        <input type="submit" value="YES" />
    </form>
    JavaScript: Learn | Validate | Compact

  8. #23
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    I uploaded your new code, I get the same error. I saw your 'Dummy Function' comment. I guess my brain is tired =) . . . I've been over this most every day for a week at several hours a day. I've looked endlessly and just can't seem to find an answer, constantly redefining my web queries. =( Please excuse me if I seem incapable at the moment.
    Last edited by KandiLyons; 11-23-2013 at 04:33 PM.

  9. #24
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    I want to mention that you've been very helpful dedicating your time and it is most appreciated.

  10. #25
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    Are you sure you've uploaded the code to the index.php file? the product_list.php file doesn't even declare that function???
    JavaScript: Learn | Validate | Compact

  11. #26
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    I did upload it and then after receiving the error I replaced it with the working pages. I will upload it again, this time I'll leave it up for a few minutes if you want to see the error. Give me two minutes.


    Edit: Done. Go ahead and look.

  12. #27
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    I see it

    Fatal error: Cannot redeclare delete_product() in /home/kandilyo/public_html/kandilyons.com/cit252project/guitar/product_manager/product_list.php on line 8
    As mentioned before, your product_list.php file doesn't declare that function. -BUT- the modified code I gave you with the dummy functions active does have it on line 8.

    The code I supplied should be used in the index.php file, under the product_manager directory. The product_list.php file should not be touched.

    I've even reproduced the error you're getting my copying the code into the wrong file :P
    Last edited by bionoid; 11-23-2013 at 05:02 PM.
    JavaScript: Learn | Validate | Compact

  13. #28
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    Oh! I just re-read what you said, no, I haven't uploaded anything to index.php. It just occurred to me what I did. Going to go fix that now. Thanks for pointing that out. Told you I was tired. =/

    Quote Originally Posted by bionoid View Post
    Are you sure you've uploaded the code to the index.php file? the product_list.php file doesn't even declare that function???

  14. #29
    Join Date
    May 2007
    Location
    Las Vegas, NV
    Posts
    42
    AH! So much better! No errors! LOL! Helps to put the code in the correct file. Okay, well, it redirects, it's not deleting, but I'm looking again at what you wrote. At least it goes back to the original page. Thanks.. I'll be back.

  15. #30
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    Yes, please use:

    index.php
    PHP Code:
    <?php

    require('../model/database.php');
    require(
    '../model/product_db.php');
    require(
    '../model/category_db.php');

    /*
    //bionoid : MY DUMMY FUNCTIONS
    function delete_product() {}
    function get_category_name($id)
    {
        return 'CATEGORY_NAME_' . $id;
    }
    function get_categories()
    {
        return array(
            array('categoryName' => 'Guitars', 'categoryID' => 2)
        );
    }
    function get_products_by_category()
    {
        return array(
            array('productCode' => '123', 'productName' => 'Product 1', 'listPrice' => '$1', 'productID' => '99', 'categoryID' => 2),
            array('productCode' => '456', 'productName' => 'Product 2', 'listPrice' => '$2', 'productID' => '45', 'categoryID' => 6)
        );
    }
    */

    if (isset($_POST['action'])) {
        
    $action $_POST['action'];
    } else if (isset(
    $_GET['action'])) {
        
    $action $_GET['action'];
    } else {
        
    $action 'list_products';
    }

    if (
    $action == 'list_products') {
        
    //the below commented area is an error
        // Get the current category ID
        /*$category_id = $_GET['category_id'];
        if (!isset($category_id)) {
            $category_id = 1;
        }*/
        //the below is the corrected version of the above
        
    if ( isset($_GET['category_id']) )
        { 
    $category_id $_GET['category_id']; }
        else
        { 
    $category_id 1; }

        
    // Get product and category data
        
    $category_name get_category_name($category_id);
        
    $categories get_categories();
        
    $products get_products_by_category($category_id);

    /*
    //below is the code to confirm a delete or deny a delete
        // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        // Delete the product
        delete_product($product_id);
        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");

    } else if ($action == 'NO') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
    */


        /*
     // Display the product list
        include('product_list.php');
    } else if ($action == 'delete_product') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];
        include('confirm.php');

    } else if ($action == 'YES') {
        // Get the IDs
        $product_id = $_POST['product_id'];
        $category_id = $_POST['category_id'];

        // Delete the product
        delete_product($product_id);

        // Display the Product List page for the current category
        header("Location: .?category_id=$category_id");
        */

    //Display the Product List page for the current category
    //header("Location: product_list.php?category_id=$category_id");


     // Display the product list
        
    include('product_list.php');

    } else if (
    $action == 'delete_product') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];

        include(
    'confirm.php'); //bionoid

        // Delete the product
        //delete_product($product_id);

        // Display the Product List page for the current category
        //header("Location: .?category_id=$category_id");


    //------------

    //bionoid
    } else if ($action == 'YES') {
        
    // Get the IDs
        
    $product_id $_POST['product_id'];
        
    $category_id $_POST['category_id'];
        
    // Delete the product
        
    delete_product($product_id);
        
    // Display the Product List page for the current category
        
    header("Location: .?category_id=$category_id");

    } else if (
    $action == 'show_add_form') {
    //    $categories = get_categories();
        
    include('product_add.php');
    } else if (
    $action == 'add_product') {
        
    $category_id $_POST['category_id'];
        
    $code $_POST['code'];
        
    $name $_POST['name'];
        
    $price $_POST['price'];

        
    // Validate the inputs
        
    if (empty($code)) {
            
    $error "The code field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $name))  {
            
    $error "The name field cannot be blank.";
            include(
    '../errors/error.php');
        } else if (empty(
    $price)) {
            
    $error "The price field cannot be blank or be a zero.";
            include(
    '../errors/error.php');
        } else if (!
    is_numeric($price))  {
            
    $error 'The price field must be a valid number.';
            include(
    '../errors/error.php');
        } else if (
    $price <= 0) {
            
    $error 'The price field must be greater than zero.';
            include(
    '../errors/error.php');
        } else {
            
    add_product($category_id$code$name$price);

            
    // Display the Product List page for the current category
            
    header("Location: .?category_id=$category_id");
        }

    }
    ?>
    JavaScript: Learn | Validate | Compact

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles