Location: PHPKode > projects > Grocery List > editGLItem.php
<?php
########################################################################
#
# Project: Grocery List
# URL: http://sourceforge.net/projects/grocery-list/
#
# Copyright: (C) 2007, James Campbell
# 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/editGLItem.php $
# Last Updated: $Date: 2010-03-06 00:03:07 -0800 (Sat, 06 Mar 2010) $
# Author(s): James Campbell
#
########################################################################

$title = 'Edit Item';
include_once("include/site.php");


$id = isset($_GET["id"]) ? $_GET["id"] : "";
$Quantity = isset($_GET["Quantity"]) ? $_GET["Quantity"] : "";
$Name = isset($_GET["Name"]) ? $_GET["Name"] : "";
$Size = isset($_GET["Size"]) ? $_GET["Size"] : "";
$Units = isset($_GET["Units"]) ? $_GET["Units"] : "";
$Mfctr = isset($_GET["Mfctr"]) ? $_GET["Mfctr"] : "";
$Notes = isset($_GET["Notes"]) ? $_GET["Notes"] : "";
$Complete = isset($_GET["Complete"]) ? $_GET["Complete"] : "";



if($Complete == "Cancel")
{
	$loc = "GroceryList.php";
	header("Location: $loc");
	exit;
}	


$connection = dbconnect();
$sql = "select * from groceries where itemid = $id";
//$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");
$sql_result = $connection->query($sql);



//$row = mysql_fetch_array($sql_result);
$row = $sql_result->fetch();
$oldquan = $row["quantity"];
$oldname = $row["itemname"];
$oldsize = $row["size"];
$oldunits = $row["units"];
$oldmfctr = $row["manufacturer"];
$oldnotes = $row["notes"];

//mysql_free_result($sql_result);

if( ($Quantity!=$oldquan) || ($Name!=$oldname) || ($Size!=$oldsize) || ($Units!=$oldunits) || ($Mfctr!=$oldmfctr) || ($Notes!=$oldnotes))
{

	if($Size == NULL)	
	{
		$sql = "update groceries set quantity = $Quantity, itemname = \"$Name\", units = \"$Units\", manufacturer = \"$Mfctr\", notes = \"$Notes\" where itemid = $id";
	}
	else
	{
		$sql = "update groceries set quantity = $Quantity, itemname = \"$Name\", size = $Size, units = \"$Units\", manufacturer = \"$Mfctr\", notes = \"$Notes\" where itemid = $id";
	}

	
	//$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query2.");
	$sql_result = $connection->query($sql);
	//mysql_free_result($sql_result);

	$loc = "GroceryList.php";
	header("Location: $loc");
	exit;


}
else
{



	$loc = "GroceryList.php";
	header("Location: $loc");
	exit;
}


//mysql_close($connection);
$connection = NULL;

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

?>
Return current item: Grocery List