include("dbconnect.php"); $locsection_id = 1; $loccategory_id = 0; $loccategory = ''; $locabstract = ''; $locorder_num = 50; if (isset($_GET["section_id"])) { // set section_id from url $locsection_id = $_GET['section_id']; // are we editing an existing category? if (isset($_GET["category_id"])) { $loccategory_id = $_GET['category_id']; } } else if (isset($_POST["category_id"])) { // set category_id from form variable $loccategory_id = $_POST['category_id']; if ($loccategory_id != 0) { //update the category $update_category_text = "UPDATE tbl_categories SET category = '". $_POST['category'] ."', abstract = '". $_POST['abstract'] ."', order_num = '". $_POST['order_num'] ."' WHERE category_id = " .$loccategory_id; $update_category = mysql_query($update_category_text); if (!$update_category) { die('Invalid query: ' . mysql_error()); } } else { // inset the category $insert_category_text = "INSERT tbl_categories (category,abstract,section_id,order_num) VALUES ('". $_POST['category'] ."','". $_POST['abstract'] ."','". $_POST['section_id'] ."','". $_POST['order_num'] ."')"; $insert_category = mysql_query($insert_category_text); if (!$insert_category) { die('Invalid query: ' . mysql_error()); } } if (isset($_POST["return"])) { header( 'Location: '.$_POST["return"] ) ; } } //get section details $qry_category_text = "SELECT category, abstract, order_num FROM tbl_categories WHERE category_id = " .$loccategory_id; $qry_category = mysql_query($qry_category_text); if (!$qry_category) { die('Invalid query: ' . mysql_error()); } While ($row = mysql_fetch_array($qry_category)) { $loccategory = $row['category']; $locabstract = $row['abstract']; $locorder_num = $row['order_num']; } //check to see if you're logged in if (isset($_COOKIE["user"])) //set the cookie to continue for another hour setcookie("user", "Eileen", time()+3600); else //redirect to the login page header( 'Location: login.php?return=edit_category.php?section_id=' .$locsection_id.'&category_id=' .$loccategory_id) ; ?>