Thanks Kyle I'll get back to it in the am.
Heres the script though. if you've nothing better to do by all means have a look, but it's not short or simple so dont worry to much about replying this time 🙂
<?
// submit.php
include("./html_library/page_starter.inc");
include("./db_library/common_db.php");
session_register("field");
session_register("next_page");
session_register("lastpage_check");
if (!$next_page) {
$next_page=FALSE;
}
$empty_msg="You are missing a field!<br>go back and check everythings in order.";
$entry_error="Could not insert data into the $table table";
$delete_partial_entry="Something went wrong and the 'partial' record has been deleted:<br> You should check this manually thogh to be sure.";
// Determine which form to show and set the $next_page
// indicator to detrmine wheather its the start of an article
// or not.
if ($page) {
print("clicked PAGE.....". $lastpage_check);
check_page_fields();
$form=nextpage();
insert_all();
$lastpage_check=$page_field[3];
$next_page=TRUE;
} elseif ($finish) {
check_page_fields();
$form=article_entry();
$lastpage_check=$page_field[3];
insert_all();
unset($field);
$next_page=FALSE;
}elseif ($head_entry) {
print("clicked HEAD.....". $lastpage_check);
check_head_fields();
$lastpage_check=$field[3];
$next_page=FALSE;
$form=nextpage();
} else {
print("clicked NOTHING.....". $lastpage_check);
unset($field);
unset($lastpage_check);
$next_page=FALSE;
$form=article_entry();
}
// template stuff
$t = new template("./templates");
$t->set_file("articles",$browser_temp);
// common var definitions
$t->set_var(array("date" => $date, "title" => $title, "keywords" => $keywords, "description" => $description, "body_color" => $body_color, "nav_color" => $nav_color, "middle_color" => $middle_color, "text_color" => $text_color));
// content
$t->set_var("content",$form);
$t->pparse("output","articles");
//******************************************
// Functions and Forms
//******************************************
function insert_data($table,$qry) {
if (!($result=mysql_query($qry))) {
return FALSE;
} else {
return TRUE;
}
}
function check_head_fields() {
global $field,$empty_msg,$lastpage_check;
if ($lastpage_check==$field[3]) {
print($empty_msg);
exit;
}
for ($i=1; $i<6; $i++) {
if (empty($field[$i])) {
print($empty_msg);
exit;
}
$field[$i]=addslashes($field[$i]);
}
return $field;
}
function check_page_fields() {
global $page_field,$empty_msg,$lastpage_check;
if ($lastpage_check==$page_field[3]) {
print($empty_msg);
exit;
}
for ($i=1; $i<4; $i++) {
if (empty($page_field[$i])) {
print($empty_msg);
exit;
}
$page_field[$i]=addslashes($page_field[$i]);
}
return $page_field;
}
function delete_last_article() {
$deleterow=mysql_insert_id();
$del_head="DELETE FROM head WHERE page_id = '$deleterow'";
$del_cont="DELETE FROM content WHERE page_id = '$deleterow'";
$del_sect="DELETE FROM section WHERE page_id = '$deleterow'";
$del=mysql_query($del_head);
$del=mysql_query($del_cont);
$del=mysql_query($del_sect);
}
function insert_all() {
global $field,$page_field,$next_page,$delete_partial_entry, $entry_error;
$insert_date=date("Y-m-d");
$sect_qry="INSERT INTO section VALUES ('NULL','$field[1]', '$field[2]')";
$cont_qry="INSERT INTO content VALUES ('NULL', '$page_field[1]', '$page_field[2]', '$page_field[3]')";
db_connect();
mysql_select_db('articles');
if (!insert_data("content",$cont_qry)) {
print($entry_error);
exit;
}
$id=mysql_insert_id();
if ($next_page==FALSE) { //inserts null if start of article
$id='NULL';
} else {
$id--; // if its a page in a series link it to the previous page
}
// now we've got $id define head query
$head_qry="INSERT INTO head VALUES ('NULL', '$id', '$insert_date', '$field[3]', '$field[4]', '$field[5]')";
if (!insert_data("head",$head_qry)) {
delete_last_article();
print($delete_partial_entry);
exit;
}
if (!insert_data("section",$sect_qry)) {
delete_last_article();
print($delete_partial_entry);
exit;
}
}
function article_entry() {
$art="";
$art .="\n<form method=\"get\" action = \"$PHP_SELF\">";
$art .="\n<p> \n<input type=\"text\" name=\"field[1]\" size=\"15\" maxlength=\"15\">";
$art .="\n<b>SECTION</b>\n</p>";
$art .="\n<p> \n<input type=\"text\" name=\"field[2]\" size=\"15\" maxlength=\"15\">";
$art .="\n<b>SUB-SECT</b>\n</p>";
$art .="\n<p> \n<input type=\"text\" name=\"field[3]\" size=\"40\" value=\"$field[3]\" maxlength=\"60\">";
$art .="\n<b>TITLE</b>\n</p>";
$art .="\n <p> \n<input type=\"text\" name=\"field[4]\" size=\"50\" maxlength=\"150\">";
$art .="\n<b>KEYWORDS</b>\n</p>";
$art .="\n<p> \n<input type=\"text\" name=\"field[5]\" size=\"50\" maxlength=\"150\">";
$art .="\n<b>DESCRIPTION</b>\n</p>";
$art .="\n<p> </p>";
$art .="\n<p>\n<input type=\"submit\" name=\"head_entry\">\n</p>";
$art .="\n</form>\n";
return $art;
}
function nextpage() {
$np="";
$np .= "\n<form method=\"get\" action=\"$PHP_SELF\">
";
$np .= "\n<p> \n<input type=\"text\" name=\"page_field[1]\" size=\"30\" maxlength=\"150\">";
$np .= "\n<b>HEADLINE</b>\n</p>";
$np .= "\n<p> \n<input type=\"text\" name=\"page_field[2]\" size=\"30\" maxlength=\"150\">";
$np .= "\n<b>SUBHEAD</b>\n</p>";
$np .= "\n<p>\n<textarea name=\"page_field[3]\" cols=\"40\" rows=\"15\">\n</textarea>\n</p>";
$np .= "\n<p>\n <input type=\"submit\" name=\"page\" value=\"Add another page?\">";
$np .= "\n<input type=\"submit\" name=\"finish\" value=\"Finish\">\n</p>";
$np .= "\n<p> </p>";
$np .= "\n</form>";
return $np;
}
?>