Location: PHPKode > projects > Grocery List > editproduct.php
<?php
########################################################################
#
# Project: Grocery List
# URL: http://sourceforge.net/projects/grocery-list/
# E-mail: hide@address.com
#
# Copyright: (C) 2010, Neil McNab
# License: GNU General Public License Version 3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Filename: $URL: https://grocery-list.svn.sourceforge.net/svnroot/grocery-list/releases/1.0/editproduct.php $
# Last Updated: $Date: 2010-03-06 00:03:07 -0800 (Sat, 06 Mar 2010) $
# Author(s): Neil McNab
#
# Description:
#   Edit or add a product in the database.
#
########################################################################

$title = "Edit Product";
$onload = "document.getElementsByName('newcat')[0].focus();";
include_once("include/header.php");

$id = $_REQUEST['id'];

$db = dbconnect();

if (isset($_REQUEST['submit'])) {
    if (empty($_REQUEST['newcat'])) {
        print "<p>ERROR: Empty Generic Product Name.</p>";
    } else {
	// handle product table first
	$expiration = $_REQUEST['exp'];
	$newcat = $_REQUEST['newcat'];

        $id = add_update_product($db, $id, $_REQUEST['newcat']);
        if ($id === NULL) {
            print "<p>query failed 2</p>";
        }
    }
}

$result = array();

if (!empty($id)) {
	$tmpresult = get_product_by_productid($db, $id);
	if (!$tmpresult) {
		print "query failed 100";
	} else {
                $result = $tmpresult->fetch();
        }
}

print '<form action="">';

print "<p><input type='hidden' name='id' value='" . $result['productid'] . "' /></p>\n";
print "<table><tr><td>Generic Product Name*:</td><td>\n";

print "<input name='newcat' value='" . $result['productname'] . "' /></td></tr>\n";
//print "<tr><td>Expiration:</td><td><input name='exp' value='" . $result['expiration'] . "' /></td></tr>\n";
//print "<tr><td>Priority:</td><td><input name='priority' value='" . $result['priority'] . "' /></td></tr>\n";

print '</table>';

print "<p><input type='submit' name='submit' value='Add/Update' /></p>";

print '</form>';

print '<p>* Required Fields</p>';

$db = NULL;

print "<p>Return to <a href='products.php'>Manage Products</a>.</p>\n";

include_once($WEBROOT . "/include/footer.php");

?>
Return current item: Grocery List