Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page Redirection Problem

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
0
0
GB
I can't understand why, having submitted a form which dispatches a couple of emails successfully, it fails to redirect to the page I have requested.
Could someone please point out where I have gone wrong here.

PHP:
// The emails:
if(mail("aa@bb.com", "Feedback", $message, "From: Dart Valley Writers") 
&& mail("noone@nowhere.com", "Feedback Alert", $inform_me, "From: Dart valley writers"))
{
header('location: [URL unfurl="true"]http://www.dartvalleywriters.org.uk/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
exit;
}else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try
again</p>';
}
}
?>

As I say, the emails are successfully sent, but the browser does not move to the page entered in the header, but goes blank, with the address bar showing the same address as brought me to this email/form page.
Thanks
 
Looks to be a syntax error with the extra curly brace. On which basis I am surprised that any part of the script works.

Also consider ensuring that headers have not already been sent by the time you get to the header() call. Headers_sent() is the function in question here.
 
Thanks jpadie, there was an error with the Curly Braces, and I've sorted that out.
However, I am still having problems. You may well be right about the headers having already been sent, but it is an area that I am pretty unclear about. (I must get to read about the subject)
In the meantime could I ask for some further help with this page? I guess what I'm looking for is "Where in the code does the problem lie?" and "What's to be done to put it right?"
Parts of the code have been lifted from a page on another site where it seemed to function fine, but on this page, with me tampering with it a bit, I am now finding that error message "You missed out your email address!" loads immediately the page loads, instead of waiting for the form to be submitted and checked.
Also I said in my first post, the emails are successfully sent, but the browser does not move to the page entered in the header, but goes blank, with the address bar showing the same address as brought me to this email/form page.
Here's the whole page, in case anyone is kind enough to help out!

PHP:
<?php require_once('../../Connections/?????.php'); ?>
<?php
session_start();
  ?>
<?php  
 $colname_rstUse = "1";
if (isset($_SESSION['NAME'])) {
  $colname_rstUse = (get_magic_quotes_gpc()) ? $_SESSION['NAME'] : addslashes($_SESSION['NAME']);
} 

$colname_rstTex = "1";
if (isset($_GET['read'])) {
  $colname_rstTex = (get_magic_quotes_gpc()) ? $_GET['read'] : addslashes($_GET['read']);	//Collects indentifying title from URL
}

$user=$_SESSION['NAME'];	//sets username variable to select records from dbase

mysql_select_db($database_tormented3, $tormented3);
$query_rstTex = sprintf("SELECT * FROM authtext WHERE username='$user' AND title='%s'", $colname_rstTex);	//Sets up Recordset from "authtext" dbase
$rstTex = mysql_query($query_rstTex, $tormented3) or die(mysql_error());
$row_rstTex = mysql_fetch_assoc($rstTex);
$totalRows_rstTex = mysql_num_rows($rstTex);

mysql_select_db($database_tormented3, $tormented3);
$query_rstAut = sprintf("SELECT * FROM authors WHERE username = '$user'");	//Sets up Recordset from "authors" dbase
$rstAut = mysql_query($query_rstAut, $tormented3) or die(mysql_error());
$row_rstAut = mysql_fetch_assoc($rstAut);
$totalRows_rstAut = mysql_num_rows($rstAut);
?>
 <?php
$reader = $_POST['reader'];		//Set up variables for email messages
$details = $_POST['feedback'];
$email = $_POST['email1'];
$auth = $row_rstAut['firstname'];		// More variables for email message
$story = $row_rstTex['title'];
if(isset($_POST['Submit']))		// 'submit' is the name of your submit button
{ 
$error = '';

 // process and validate a field: 
  $email = trim($_POST['email1']); 
  }
 if($email == ''){ // if name is empty, show an error message (us that for required fields)
 $error .= '<p style="color:red;">You missed out your email address!</p>'; // error message
 }
 if($error == '')
 { // if no error, process the form 

// place here your mail script 
$message = "Dear $auth, You have had feedback from the U3A Writers Website\n";	// Set up the email message to the client.
$message .= "about your piece, $story, from $reader, as follows:\n\n";
$message .= " $details .\n\n";
$message .= "$reader's email address is $email. \n";

$inform_me = "Feedback re. $story have been sent to $auth"; // Set up the email to inform me of the information request.
// The emails:
if(mail("aa@bb.com", "Feedback", $message, "From: Dart Valley Writers") 
&& mail("noone@nowhere.com", "Feedback Alert", $inform_me, "From: Dart valley writers"))
//{
header('location: [URL unfurl="true"]http://www.dartvalleywriters.org.uk/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
exit;
}
else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try
again</p>';
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>Feedback Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css.css" rel="stylesheet" type="text/css">
</head>

<body>
<!-- DO NOT MOVE! The following AllWebMenus linking code section must always be placed right AFTER the BODY tag-->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR menu ******** -->
<script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="menu",awmBN="922";</script><script charset="UTF-8" src="menu/menu.js" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
<!-- ******** END ALLWEBMENUS CODE FOR menu ******** -->
<div id="wrapper">
<table width="98%"  border="0">
  <tr>
    <td><table width="100%"  border="0">
      <tr class="bluecell">
        <td colspan="2"><p>&nbsp;</p>
          <p>Dart Valley Writers U3A</p>
          <p>&nbsp;</p></td>
        <td colspan="2">&nbsp<?php echo $error; ?></td>
        <td width="1%">&nbsp;</td>
        <td width="4%">&nbsp; </td>
      </tr>
      <tr>
        <td width="23%" class="bluecell">&nbsp;</td>
        <td width="15%" class="up_right" id="awmAnchor-menu">&nbsp;</td>
        <td width="19%" class="up_right"><h6>"<?php echo $row_rstTex['title'] ;?>"</h6></td>
        <td colspan="2" class="textcell">by <?php echo $row_rstAut['firstname']; ?>&nbsp;<?php echo $row_rstAut['surname']; ?> </td>
        <td class="bluecell">&nbsp;</td>
      </tr>
      <tr>
        <td class="bluecell">&nbsp;</td>
        <td class="up_right"><p>&nbsp;</p>
          <p>Your name : </p>
          <p>Your email address : </p>
          <p>&nbsp;</p>
          <p><span class="textcell">Your Feedback : </span></p>
          </td>
        <td colspan="2" class="textcell"><form name="email1" method="POST" >
          <p>&nbsp;            </p>
          <p>
            <input name="reader" type="text" id="reader" size="50">
          </p>
          <p>
            <input name="email1" type="text" id="email1" size="60">
          </p>
          <p>&nbsp;</p>
          <p>
            <textarea name="feedback" cols="70" rows="6" id="feedback"></textarea>
                    </p>
          <p>
            <input type="submit" name="Submit" value="Submit">      
                </p>
        </form>          <p align="left">&nbsp;</p>
          <p align="left">&nbsp;</p></td>
        <td class="textcell">&nbsp;</td>
        <td class="bluecell">&nbsp;</td>
      </tr>
      <tr>
        <td class="bluecell">&nbsp;</td>
        <td class="bluecell">&nbsp;</td>
        <td colspan="2" class="bluecell">&nbsp;</td>
        <td class="bluecell">&nbsp;</td>
        <td class="bluecell">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<p>&nbsp;</p>
</div>
</body>
</html>
<?php
mysql_free_result($rstTex);
mysql_free_result($rstAut);
?>

Many thanks for any assistance.
 
Code:
 <?php
$reader = $_POST['reader'];		//Set up variables for email messages
$details = $_POST['feedback'];
$email = $_POST['email1'];
$auth = $row_rstAut['firstname'];		// More variables for email message
$story = $row_rstTex['title'];
if(isset($_POST['Submit']))		// 'submit' is the name of your submit button
{ 
$error = '';

 // process and validate a field: 
  $email = trim($_POST['email1']); 
  [red][s]}[/s][/red]
 if($email == ''){ // if name is empty, show an error message (us that for required fields)
 $error .= '<p style="color:red;">You missed out your email address!</p>'; // error message
 }
 if($error == '')
 { // if no error, process the form 

// place here your mail script 
$message = "Dear $auth, You have had feedback from the U3A Writers Website\n";	// Set up the email message to the client.
$message .= "about your piece, $story, from $reader, as follows:\n\n";
$message .= " $details .\n\n";
$message .= "$reader's email address is $email. \n";

$inform_me = "Feedback re. $story have been sent to $auth"; // Set up the email to inform me of the information request.
// The emails:
if(mail("aa@bb.com", "Feedback", $message, "From: Dart Valley Writers") 
&& mail("noone@nowhere.com", "Feedback Alert", $inform_me, "From: Dart valley writers"))
//{
header('location: [URL unfurl="true"]http://www.dartvalleywriters.org.uk/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
exit;
}
else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try
again</p>';
}
[red]}[/red]
?>
 
Thanks again, jpadie.
The extra curly-brace you added at the bottom just produced the error "Parse error: syntax error, unexpected '}' in /homepages/35/d406485504/htdocs/hopeless/writers2/feedback.php on line 67", so I went back to one.
However, progress has been made! I removed the white-space in front of the <?php, as you had done, and the empty lines, and then found that the page did re-direct as required.
Th oddity that remains is that I am still finding that error message "You missed out your email address!" loads immediately the page first loads, instead of waiting for the form to be submitted and checked to see if the email address is there or not.
Any thoughts?
 
apologies. i did not run the result through a syntax checker

i have cleaned up the code a bit to use nicer indenting and heredoc etc so it becomes much easier to see where you are going wrong.

Code:
<?php
$reader = $_POST['reader'];        //Set up variables for email messages
$details = $_POST['feedback'];
$email = $_POST['email1'];
$auth = $row_rstAut['firstname'];        // More variables for email message
$story = $row_rstTex['title'];
if(isset($_POST['Submit'])):    // 'submit' is the name of your submit button

    $error = '';
    // process and validate a field: 
      $email = trim($_POST['email1']); 
     if($email == ''):// if name is empty, show an error message (us that for required fields)
         $error .= '<p style="color:red;">You missed out your email address!</p>'; // error message
     endif;
     if($error == ''): // if no error, process the form 

// place here your mail script 
    $message = <<<TXT
Dear $auth, You have had feedback from the U3A Writers Website
about your piece, $story, from $reader, as follows:

$details 
$reader's email address is $email. 
TXT;

    $inform_me = <<<TXT
Feedback re. $story have been sent to $auth

TXT;
    if(
        mail("aa@bb.com", "Feedback", $message, "From: Dart Valley Writers") 
        && 
        mail("noone@nowhere.com", "Feedback Alert", $inform_me, "From: Dart valley writers")
        ):
        header('location: [URL unfurl="true"]http://www.dartvalleywriters.org.uk/email_redirect.php');//[/URL] redirect to page if email has been successfully sent
        exit;
    else:
        $error == '<p style="color:red;">An error occured, your email could not be sent. Please try again</p>';
    endif;
endif; // no submission so don't do anything
?>
 
Is there supposed to be only one equal sign after $error?
 
That's really good of you to take so much time and effort!
However, your improved code produces:
Parse error: syntax error, unexpected end of file in /homepages/35/d406485504/htdocs/hopeless/writers2/feedback.php on line 152

 
To clarify my previous post, I was referring to this line:
Code:
$error == '<p style="color:red;">...
This is not a conditional statement so only one equal sign would apply.

In regard to the syntax error on line 152, what is on line 152?
 
@spamjim

No - that's clearly an error . good spot.
But it is not a fatal error and would not throw off the script.

I too would like to know what line 152 is.

I think there should another endif; at the end of the above codeblock too.
 
1. Thanks, spamjim, I have removed one of the equal signs.
2. There is no line 152 on the coded page, only 146 lines of code.
3. Good News! The extra "endif; has eased the log-jam. The email error notice no longer arises unless appropriate.
Thanks for all the help, folks. I really appreciate it.
¡Hasta la proxima!



 
Just to clarify, The web page is now functioning, send the emails and redirects to the correct URL.
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top