Location: PHPKode > scripts > Shopping Cart - Shopping list application > shopping-cart-shopping-list-application/edititem.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
		<title>Edit Item</title>
	</head>

	<? include "config.php"; 

$item=$_REQUEST["item"];
$olditem=$_REQUEST["olditem"];
$save=$_REQUEST["save"];
$del=$_REQUEST["Delete"];
if ($del=="Del" && $item==$olditem) {
		if ($del=="Del") {
			mysql_query("delete from item where id=$item");
			$item=0;
		}
}
if ($save=="Save") {
	$product=$_REQUEST["product"];
	$isle=$_REQUEST["isle"];
	if ($isle=="") $isle=99;
	$price=$_REQUEST["price"];
	$shop=$_REQUEST["shop"];
	if ($item==0) {
		$q="insert into item values (0,\"$product\",$shop,$isle,0,0,1,\"$price\")";
		mysql_query($q);
		$item=mysql_insert_id();
	}
	if ($item==$olditem) {	// Daten editieren/aktualisieren
		if ($item>0) {
			$q="update item set product=\"$product\", shop=$shop, isle=$isle, price=\"$price\" where id=$item";
			mysql_query($q);
		}
	}
}

?>

	<body bgcolor="#bab9f8">
		<form id="EditItem" action="edititem.php" method="post" name="EditItem">
			<table width="100%" border="0" cellspacing="2" cellpadding="0">
				<tr>
					<th>Edit Item:</th>
					<td><select name="item" size="1" onchange="submit()">
							<option selected="selected" value="0">New</option><? $q="select * from item order by product,id";
							$r=mysql_query($q);
							$n=mysql_num_rows($r);
							for ($t=1;$t<=$n;$t++) {
								$data=mysql_fetch_row($r);
								print "<option ";
								if ($item==$data[0]) {
									print "selected=\"selected\"";
									$sel=$data;
								}
								print "value=\"$data[0]\">$data[1]</option>\n";
							}
							?>
						</select><input type="submit" name="edit" value="Go" /> <input type="hidden" name="olditem" value="<? print $item; ?>" /></td>
				</tr>
				<tr>
					<td align="right">Product:</td>
					<td><input type="text" name="product" value="<? print $sel[1] ?>" size="24" /></td>
				</tr>
				<tr>
					<td align="right">Shop:</td>
					<td><select name="shop" size="1">
							<option value="0">any</option><?
							$q="select * from shop order by name";
							$r=mysql_query($q);
							$n=mysql_num_rows($r);
							for ($t=1;$t<=$n;$t++) {
								$data=mysql_fetch_row($r);
								print "<option ";
								if ($sel[2]==$data[0]) print "selected=\"selected\"";
								print "value=\"$data[0]\">$data[1]</option>\n";
							}
?>
						</select></td>
				</tr>
				<tr>
					<td align="right">Isle:</td>
					<td><input type="text" name="isle" value="<? print $sel[3]; ?>" size="3" maxlength="3" /></td>
				</tr>
				<tr>
					<td align="right">Price:</td>
					<td><input type="text" name="price" value="<? print $sel[7]; ?>" size="10" maxlength="10" /></td>
				</tr>
				<tr>
					<th align="center"><a href="index.php">Back</a></th>
					<td><input type="submit" name="save" value="Save" /><input type="submit" name="Delete" value="Del" /></td>
				</tr>
			</table>
		</form>
		<p></p>
	</body>

</html>
Return current item: Shopping Cart - Shopping list application