Jump to content


Check Conditions - Update & Go To New Page?

  • Please log in to reply
3 replies to this topic

#1 Mr Chris

Mr Chris
  • Members
  • PipPipPip
  • Advanced Member
  • 336 posts

Posted 28 June 2006 - 02:36 PM

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> 

#2 Buyocat

  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 28 June 2006 - 02:41 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 Mr Chris

Mr Chris
  • Members
  • PipPipPip
  • Advanced Member
  • 336 posts

Posted 28 June 2006 - 03:07 PM


Thanks for your help. This problem is bizzare though. My site is hosted as a .org 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 .net

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


#4 freakus_maximus

  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 28 June 2006 - 04:07 PM

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.

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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users