Jump to content


This topic is now archived and is closed to further replies.

Mr Chris

Check Conditions - Update & Go To New Page?

Recommended Posts

Hi Guys,

Thought I had this correct in my head after inspiration found on forum last night.

With the below 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

It does not go to the URL I specify when submit is hit?


//Connect to DB

    $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'];

    $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>";
//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: [url=http://www.site.org/site/new_site/stories/confirm_edited_story.php?story_id='.$_POST]http://www.site.org/site/new_site/stories/...39;.$_POST[/url]['story_id']);  
       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">
<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">

<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>

Share this post

Link to post
Share on other sites
header("Location: [a href=\"http://yoursitehere.com");\" target=\"_blank\"]http://yoursitehere.com");[/a]

Also I suggest that you make your query like this:
$_query = "UPDATE ... "
$_result = @mysql_query($_query);

It's just a little easier to read and update that way, you might do the same thing for the URL in the redirect which looked pretty long...

$_url = 'http://....';
header("Location: " . $url);

Something like that.

Share this post

Link to post
Share on other sites

Thanks for your help. This problem is bizzare though. My site is hosted as a [b].org[/b] domain name. So:

The re-direct does not work on:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]header('Location: [a href=\"http://www.slougheaz.org/site/new_site/stories/confirm_edited_story.php');\" target=\"_blank\"]http://www.slougheaz.org/site/new_site/sto...tory.php');[/a] [/quote]

But if I was to change it to a [b].net[/b]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]header('Location: [a href=\"http://www.slougheaz.net/site/new_site/stories/confirm_edited_story.php');\" target=\"_blank\"]http://www.slougheaz.net/site/new_site/sto...tory.php');[/a] [/quote]

So is this a case of it not liking the .org domain or just not liking to re-direct on the same site as the file is located?

Many Thanks


Share this post

Link to post
Share on other sites
Hard to read the way that code is pasted, but the one thing that stands out is that your FORM ACTION= is not stated.

You should have either the page that is handling the processing of the form there or PHP_SELF if you are having it process on the same page.

[code]<FORM ACTION="" METHOD="post" NAME="frmAdd"> <TABLE WIDTH="100%" BORDER="0" ALIGN="center"> [/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.