Hi Guys,
Thought I had this correct in my head after a brilliant explanation by Houdini last night.
With this script that edits a record.
- It gets a record from the database checks all required fields have been filled in and outputs a message if a field is missed
- It submits and updates the data to the database if all fields are filled in
But…
It does not go to the URL I specify when submit is hit?
<?php
//Connect to DB
include("*********8");
if(isset($_GET['story_id']))
{
$result = mysql_query("Select * From cms_stories where story_id=".$_GET['story_id']);
$row = mysql_fetch_array($result);
$section = $row['section'];
$added_by = $row['added_by'];
$headline = $row['headline'];
$byline_name = $row['byline_name'];
$appeared = $row['appeared'];
$published = $row['published'];
$opening = $row['opening'];
$body_text = $row['body_text'];
$notes = $row['notes'];
}
if(isset($_POST['Submit']))
{
$story_id = $_POST['story_id'];
$section = $_POST['section'];
$added_by = $_POST['added_by'];
$headline = $_POST['headline'];
$byline_name = $_POST['byline_name'];
$appeared = $_POST['appeared'];
$published = $_POST['published'];
$opening = $_POST['opening'];
$body_text = $_POST['body_text'];
$notes = $_POST['notes'];
if (empty($section)){
$error = "** You forgot to enter the section for the story! **<br>";
} else if (empty($added_by)){
$error .= "** Error: You forgot to who added the story! **<br>";
} else if (empty($headline)){
$error .= "** Error: You forgot to enter a headline for the story! **<br>";
} else if (empty($byline_name)){
$error .= "** Error: You forgot to enter a byline name for the story! **<br>";
} else if (empty($published)){
$error .= "** Error: You forgot to the date you wish to publish the story! **<br>";
} else if (empty($opening)){
$error .= "** Error: You forgot to the Opening Paragraph for the Indexes! **<br>";
} else if (empty($body_text)){
$error .= "** Error: You forgot to enter any body text! **<br>";
};
if($error==''){
//no text is in $error so the data is submitted to the database
$result = mysql_query("Update cms_stories set section='$section', added_by='$added_by', headline='$headline', byline_name='$byline_name', appeared='$appeared', published='$published', opening='$opening', body_text='$body_text', notes='$notes' where story_id=$story_id");
//But the header location does not change? It still stays on the same URL When submit is hit
header('Location: http://www.site.org/site/new_site/stories/confirm_edited_story.php?story_id='.$_POST['story_id']);
}
else{
echo "<span style=color:red>$error</span>";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>test site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../login/ssheet.css">
<script language="JavaScript" src="scripts/calendar1.js"></script>
<script language="JavaScript" src="scripts/calendar2.js"></script>
<link rel="stylesheet" href="../include/css_table.css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<FORM ACTION="" METHOD="post" NAME="frmAdd"> <TABLE WIDTH="100%" BORDER="0" ALIGN="center">
<TR> <TD HEIGHT="24"><INPUT TYPE='hidden' NAME='story_id' VALUE='<?php echo $_GET['story_id']; ?>'/>
</TD></TR> </TABLE><BR> <TABLE WIDTH="100%" BORDER="0"> <TR> <TD WIDTH="12%"><B>Section:
</B></TD><TD WIDTH="88%"> <SELECT NAME="section"> <OPTION><?php echo $section?></OPTION>
<OPTION VALUE="art_and_culture">Art & Culture</OPTION> <OPTION VALUE="business">Business</OPTION>
<OPTION VALUE="clubs_and_societies">Clubs & Societies</OPTION> <OPTION VALUE="information_services">Information
Services</OPTION> <OPTION VALUE="leisure_venues">Leisure Venues</OPTION> <OPTION VALUE="organisation_links">Orgaisation
Links</OPTION> <OPTION VALUE="religion_links">Religion Links</OPTION> <OPTION VALUE="residents_homepages">Residents
Homepages</OPTION> <OPTION VALUE="sports_clubs">Sports Clubs</OPTION> <OPTION VALUE="student_links">Student
Links</OPTION> </SELECT> </TD></TR> <TR> <TD WIDTH="12%"><B>Added by: </B></TD><TD WIDTH="88%">
<INPUT NAME="added_by" TYPE="text" ID="added_by" VALUE="<?php echo $added_by?>" SIZE="50">
</TD></TR><TR><TD WIDTH="12%" HEIGHT="13">Headline</TD><TD WIDTH="88%" HEIGHT="13"><INPUT NAME="headline" TYPE="text" ID="headline" VALUE="<?php echo $headline?>" SIZE="50"></TD></TR><TR><TD WIDTH="12%">Byline
Name </TD><TD WIDTH="88%"><INPUT NAME="byline_name" TYPE="text" ID="byline_name" VALUE="<?php echo $byline_name?>" SIZE="50"></TD></TR><TR><TD WIDTH="12%" HEIGHT="13">Appeared</TD><TD WIDTH="88%" HEIGHT="13"><INPUT NAME="appeared" TYPE="text" ID="appeared" VALUE="<?php echo $appeared?>" SIZE="50"></TD></TR><TR><TD WIDTH="12%">Published</TD><TD WIDTH="88%"><INPUT NAME="published" TYPE="text" ID="published" VALUE="<?php echo $published?>" SIZE="50"></TD></TR><TR><TD WIDTH="12%">Opening</TD><TD WIDTH="88%"><INPUT NAME="opening" TYPE="text" ID="opening" VALUE="<?php echo $opening?>" SIZE="50"></TD></TR><TR><TD WIDTH="12%">body
text </TD><TD WIDTH="88%"><INPUT NAME="body_text" TYPE="text" ID="body_text" VALUE="<?php echo $body_text?>" SIZE="50"></TD></TR><TR><TD WIDTH="12%">Notes</TD><TD WIDTH="88%"><INPUT NAME="notes" TYPE="text" ID="notes" VALUE="<?php echo $notes?>" SIZE="50"></TD></TR>
</TABLE><P> <INPUT TYPE="Submit" NAME="Submit" VALUE="Submit"> <INPUT TYPE="reset" NAME="Reset" VALUE="Clear Story">
</P></FORM><P> <A HREF="edit.php">Back to Links Index</A> <P>
</body>
</html>