Hey roggers, sorry for the misunderstanding. What I meant by cleaning up code were suggestions to where I could take 5 lines of code and shrink it to 1 or 2 lines. I cleaned out everything I could find that was no longer needed though. Here are the 4 pages. I really appreciate your guys help! If you would rather have me upload the files in a zip file let me know. Thanks again!!!
series.php
This is the main file with all the functions. It also calls the last 3 files with includes, but everything pretty much happens in this file.
<?
/******************************************************************************
* MAIN
*****************************************************************************/
include("application.php");
/*require_login();
require_priv("admin");*/
$DOC_TITLE = "Catalyst Series Management";
include("templates/header.php");
if (isset($_GET["action"])){
$action = $_GET["action"];
} else {
"";
}
if (isset($_GET["id"])){
$id = $_GET["id"];
} else {
"";
}
switch (nvl($action)) {
case "add" :
print_add_series_form();
break;
case "edit" :
print_edit_series_form();
break;
case "del" :
delete_series();
print_series_list();
break;
case "insert" :
insert_series();
print_series_list();
break;
case "update" :
update_series();
print_series_list();
break;
default :
print_series_list();
break;
}
include("templates/footer.php");
/******************************************************************************
* FUNCTIONS
*****************************************************************************/
function print_add_series_form() {
/* print a blank series form so we can add a new series */
global $CFG, $ME;
$query ="SELECT max(ID) FROM series";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$row = mysql_fetch_row($result);
//echo $row[0]+1;
$script_id= $row[0]+1;
$frm = db_fetch_array($qid);
/* set default values for the reset of the fields */
$frm["id"] = $script_id;
$frm["newaction"] = "insert";
$frm["title"] = "";
$frm["link"] = "";
$frm["submit_caption"] = "Add Series";
include("templates/series_form.php");
}
function print_edit_series_form() {
/* print a series form so we can add a edit the selected series */
global $CFG, $ME;
/* load up the information for the series */
$qid = db_query("
SELECT id, series, link, title, image
FROM series
WHERE id = $id
");
$frm = db_fetch_array($qid);
/* set values for the form */
$frm["id"] = $frm["id"];
$frm["newaction"] = "update";
$frm["submit_caption"] = "Save Changes";
include("templates/series_form.php");
}
function delete_series() {
/* delete the series specified by $id. */
global $CFG, $ME;
$id = $_GET['id'];
/* delete this series */
$qid = db_query("
DELETE FROM series WHERE ID = $id
");
include("templates/series_deleted.php");
}
function insert_series() {
/* add a new series. */
global $CFG, $ME;
$ID = $_POST['ID'];
$TITLE = $_POST['TITLE'];
$LINK = $_POST['LINK'];
$SERIES = $_POST['SERIES'];
$IMAGE = $_POST['IMAGE'];
$qid=db_query("INSERT INTO series (ID, Title, Link, Series, Image) VALUES ('".mysql_real_escape_string($ID)."','".mysql_real_escape_string($TITLE)."','".mysql_real_escape_string($LINK)."','".mysql_real_escape_string($SERIES)."','".mysql_real_escape_string($IMAGE)."')");
}
function update_series() {
/* update the series $id with new values.*/
global $CFG, $ME;
$ud_ID = $_POST['ud_ID'];
$ud_TITLE = $_POST['ud_TITLE'];
$ud_LINK = $_POST['ud_LINK'];
$ud_SERIES = $_POST['ud_SERIES'];
$ud_IMAGE = $_POST['ud_IMAGE'];
$qid = db_query("
UPDATE series SET ID='$ud_ID', Title='$ud_TITLE', Link='$ud_LINK', Series='$ud_SERIES', Image='$ud_IMAGE' WHERE ID='$ud_ID'
");
}
function print_series_list() {
/* read all the series from the database and print them into a table.*/
global $CFG, $ME;
$qid = db_query("
SELECT id, title, link, series, image
FROM series
WHERE id > 0
ORDER BY id DESC
");
include("templates/series_list.php");
}
?>
series_list.php
html for a table that list all records from the list query in series.php
<p class=normal>
<?
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
<br />
<a href="<?=$ME?>?action=add">[+C] Add Category</a><br />
</p>
<table border=1 cellpadding=3>
<tr>
<th>Action</th>
<th>Series</th>
<th>Link</th>
<th>Title</th>
<th>Image</th>
</tr>
<? while ($r = db_fetch_object($qid)) { ?>
<tr>
<td class=normal align="center">
[ <a title="Delete <? pv($r->series) ?>" href="<?=$ME?>?action=del&id=<? pv($r->id) ?>">X</a>
]
</td>
<td class=normal><a title="Edit this category" href="<?=$ME?>?action=edit&id=<? pv($r->id) ?>"><? pv($r->title) ?></a></td>
<td class=normal><? pv($r->link) ?></td>
<td class=normal><? pv($r->series) ?></td>
<td class=normal><? pv($r->image) ?></td>
</tr>
<? } ?>
</table>
series_form.php
html for the insert/edit record form. one of 2 forms is displayed based on the action value.
<?
if (isset($_GET["action"])){
$action = $_GET["action"];
} else {
"";
}
?>
<?
if ($action=="add") {
?>
<?
$query ="SELECT max(ID) FROM series";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$row = mysql_fetch_row($result);
//echo $row[0]+1;
$script_id= $row[0]+1;
?>
<form method="post" action="<?=$ME?>?action=<?=$frm["newaction"]?>">
<input type="hidden" name="action" value="<?=$frm["newaction"]?>">
ID:<br />
<input type="text" name="ID" size="4" value="<?= $script_id ?>" /><br />
Title:<br />
<input type="text" name="TITLE" size="100" /><br />
Link:<br />
<input type="text" name="LINK" size="100" /><br />
Series:<br />
<input type="text" name="SERIES" size="100" /><br />
Image:<br />
<input type="text" name="IMAGE" size="100" /><br />
<input type="submit" value="Update Database" />
</form>
<?
} else {
/*echo "EDIT!!!!";*/
?>
<?php
$res=mysql_query(" SELECT * FROM series WHERE id='$id'");
mysql_close();
if (mysql_num_rows($res)==0) echo "There is no data in the table";
else
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
$ID=stripslashes($row["ID"]);
$TITLE=stripslashes($row["Title"]);
$LINK=stripslashes($row["Link"]);
$SERIES=stripslashes($row["Series"]);
$IMAGE=stripslashes($row["Image"]);
}
?>
<form method="post" action="<?=$ME?>?action=<?=$frm["newaction"]?>">
<input type="hidden" name="action" value="<?=$frm["newaction"]?>">
ID: <input type="text" name="ud_ID" value="<? echo $ID; ?>"><br>
Title: <input type="text" name="ud_TITLE" value="<? echo $TITLE; ?>"><br>
Link: <input type="text" name="ud_LINK" value="<? echo $LINK; ?>"><br>
Series: <input type="text" name="ud_SERIES" value="<? echo $SERIES; ?>"><br>
Image: <input type="text" name="ud_IMAGE" value="<? echo $IMAGE; ?>"><br>
<input type="Submit" value="Update">
</form>
<?
}
?>
series_delete.php
text that shows what record was deleted when the del function is run from series.php.
<p class=normal>
The category <b><? pv($cat->name) ?></b> has been deleted. All the products and
sub-categories belonging to <b><? pv($cat->name) ?></b> have been reassigned to
<b><? pv($cat->parent) ?></b>.
One question though. I can not get the action value through $_POST. I've got something goofed, but I don't know where. I know the value is posting because it appears with this
<p class=normal>
<?
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
in the series_list.php. However, whatever I try I can not get the posted value, I can only get it through the $_GET command though the URL. What gives?