Location: PHPKode > scripts > phpGiftList > phpgiftlist/adminadmin.php
<html>

<body>
<!-- phpGiftList - a gift list manager written in PHP and using mySQL
    Copyright (C) 2000  O.M. Jenkins
    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; either version 2 of the License, or
    (at your option) any later version.
    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, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->

<h1>phpProject Admin Page</h1>
<a href="<?php echo $PHP_SELF?>">New Project</a> |
<a href="admindisplay.php">Display Giftlist</a>



<?php

$db = mysql_connect("localhost", "root");

mysql_select_db("giftlist",$db);

if($submit) {
	
	// here if no ID then adding else we're editing
	
	if ($id) {

		$sql = "UPDATE item SET item_name='$item_name',item_desc='$item_desc',item_hidden='$item_hidden',item_price='$item_price',item_misc='$item_misc',item_size='$item_size',URL='$URL',item_vendor='$item_vendor' WHERE id=$id";

	} else {

		$sql = "INSERT INTO item (item_name,item_desc,item_hidden,item_price,item_misc,item_size,URL,item_vendor) VALUES ('$item_name','$item_desc','$item_hidden','$item_price','$item_misc','$item_size','$URL','$item_vendor')";

	}

	// run SQL against the DB

	$result = mysql_query($sql);

	echo "<br>Record updated/edited!<p>";

	} elseif ($delete) {

		// delete a record

		$sql = "DELETE FROM item WHERE id=$id";

		$result = mysql_query($sql);
		
		echo "<br> Record deleted!<p>";

	} else {

	// this part happens if we don't press submit

	if (!$id) {

		// print the list if there is no editing

		$result = mysql_query("SELECT * FROM item",$db);

		while ($myrow = mysql_fetch_array($result)) {

			
		//	printf("<li><a href=\"%s?id=%s\">%s</a>\n", $PHP_SELF, $myrow["id"], $myrow["proj_name"]);
				
		//		printf("<a href=\"%s?id=%s&delete=yes\">(Del)</a><br>", $PHP_SELF, $myrow["id"]);

		}

	}

?>

<p>

<h2>Data Form</h2>
<form method="post" action="<?php echo $PHP_SELF?>">

<?php


if ($id) {

	// editing so select a record

	$sql = "SELECT * FROM item WHERE id=$id";

	$result = mysql_query($sql);

	$myrow = mysql_fetch_array($result);

	$id = $myrow["id"];

	$item_name = $myrow["item_name"];

	$item_desc = $myrow["item_desc"];

	$item_hidden = $myrow["item_hidden"];

	$item_price = $myrow["item_price"];

	$item_misc = $myrow["item_misc"];

	$item_size = $myrow["item_size"];

	$URL = $myrow["URL"];

	$item_vendor = $myrow["item_vendor"];

	// print the id for editing


	?>

	<input type=hidden name="id" value="<?php echo $id ?>">

	<?php

}
	
?>


Item name:<input type="Text" name="item_name" value="<?php echo $item_name ?>"><br>

Description:<input type="Text" name="item_desc" value="<?php echo $item_desc ?>"><br>

Item Hidden? (Y or N):<input type="Text" name="item_hidden" value="<?php echo $item_hidden ?>"><br>

Item price (include 2 decimal places i.e., 22.00):<input type="Text" name="item_price" value="<?php echo $item_price ?>"><br>

Misc. info (color, etc.):<input type="Text" name="item_misc" value="<?php echo $item_misc ?>"><br>

Item size:<input type="Text" name="item_size" value="<?php echo $item_size ?>"><br>

URL to buy online(This field on this form is BUGGY):<input type="Text" name="URL" value="<?php echo $URL ?>"><br>

Item Vendor:<input type="Text" name="item_vendor" value="<?php echo $item_vendor ?>"><br>

<br>

<input type="Submit" name="submit" value="Enter Information">

</form>

<?php


}


?>


</body>

</html>
	
Return current item: phpGiftList