<?php
// start the session
session_start();
// is the one accessing this page logged in or not?
if (!isset($_SESSION['basic_is_logged_in'])
|| $_SESSION['basic_is_logged_in'] !== true) {
// not logged in, move to login page
header('Location: index.php');
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>X-Mas Gift Database</title>
<style type="text/css">@import url("style.css");</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h2>X-Mas Gift Database</h2>
<br>
<?php
if(isset($_POST['add']))
{
include 'config.php';
include 'lib/opendb.php';
$id = $_GET['id'];
$name = $_POST['name'];
$gift = $_POST['gift'];
$got = $_POST['got'];
$query = "UPDATE gifts SET name = '$name', gift = '$gift', got = '$got' WHERE id = $id";
mysql_query($query) or die('Error, update query failed');
$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert2 query failed');
include 'lib/closedb.php';
echo "<h3>Gift Updated Successfully!</h3><BR>";
}
else
{}
?>
<?php
include 'config.php';
include 'lib/opendb.php';
$id = $_GET['id'];
$query = "SELECT id, name, gift, got FROM gifts WHERE id=$id";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$id=$row["id"];
echo "
<form method=\"post\" name=\"add\" action=\"modify.php?id=$id\">
<p align=\"center\">
<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
<tr>
<td width=\"250\">Name</td>
<td><input name=\"name\" size=\"35\" type=\"text\" id=\"name\" value=\"{$row['name']}\"></td>
</tr>
<tr>
<td width=\"250\">Gift</td>
<td><input name=\"gift\" size=\"35\" type=\"text\" id=\"gift\" value=\"{$row['gift']}\"></td>
</tr>
<td width=\"250\">Got It?</td>
<td><select name=\"got\"><option value =\"{$row['got']}\">Currently ({$row['got']})</option><option value =\"Yes\">Yes</option><option value =\"No\">No</option></select></td>
</tr>
</table><br>
<p align=\"center\"><input type=\"button\" class=\"btn\" onClick=\"window.location='list.php'\" value=\"Back\"> <input class=\"btn\" name=\"add\" type=\"submit\" id=\"add\" value=\"Update Gift\"></p>
</form>";
}
?>
</body>
</html>