header not redirecting

This is a discussion on "header not redirecting" within the PHP Forum section. This forum, and the thread "header not redirecting are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 3rd, 2005, 14:58
New Member
Join Date: Nov 2005
Location: U.K
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pilch Send a message via MSN to pilch Send a message via Skype™ to pilch
Wink header not redirecting

Hello everyone.

I've finished the front end and admin sections of a reviews db im working on albeit I've just started looking into user validation, herewith lies the issue.

Basically the $error checking works fine as I proved it by simply outputting an echo $error. I thought I'd go to the next stage and try a header redirect. what it should do if !empty($error is to redirect me to the authors_admin_action.php page along with the author id and $error. But it's not..

I'm aware that you cant have any HTML in the page or something for these php header redirects to work so I had commented out the include "includes/adminheader.inc.php" line as that does include HTML.

If anyone could help me I'd be really grateful.. p.s I've only just started so all my tryouts lend themselves to when you EDIT an author's name...

Here's the code for the file that is responsible for sql insertion/editing + checking.. commit_authors.php

PHP: Select all

  <?
 
// COMMIT ADD AND EDITS
 
 // reset variable $error to empty (added for form validation)
 
$error '';
 
//database connectivity include
 
include "../includes/dbinfo_test.inc.php";
 include 
"includes/adminheader.inc.php";
 
?>
  <style type="text/css">
 <!--
@import url("../css/stylesadmin.css");
.style2 {
    color: #FF0000;
    font-weight: bold;
    font-size: 12px;
}
 -->
 </style>
 <?
  
switch ($_GET['action']) {
    case 
"edit":
      switch (
$_GET['type']) {
        case 
"author":
        
$author_name trim($_POST['author_name']);
        if (empty(
$author_name)) {
          
$error .= "Please+enter+an+author+name%21%0D%0A";
        }
        if (empty(
$error)) {
          
$sql "UPDATE author SET
                    authorname = '" 
$_POST['author_name'] . "'
                  WHERE authorid = '" 
$_GET['id'] . "'";
        } else {
          
// the below code doesn't redirect neither does it output any error - very odd
          
header("location:authors_admin_action.php?action=edit&error=" .
                 
$error "&id=" $_GET['id'] );
        }
        break;
      }
      break;
    case 
"add":
      switch (
$_GET['type']) {
        case 
"author":
          
$sql "INSERT INTO author
                    (authorname) 
                  VALUES
                    ('" 
$_POST['author_name'] . "')";
          break;
      }
      break;
  }
  
// Tests that $sql is set and not empty
  
if (isset($sql) && !empty($sql)) {
    echo 
"<!--" $sql "-->";          //  output $sql for debugging purposes (currently remmed out)
    // sending the results to the server.
    
$result mysql_query($sql) or die("Invalid query: " mysql_error()); 
      
  
?>
  <div id="Content">
  <span class="style2">Records changed:</span>
  <br />
  <hr />
  <? echo $sql ?>
  <br />
  <br />
  </div>
    <?php
  
}
?>
Here's the code for the file that lists the authors and allows you to EDIT or ADD. authors_admin_action.php

PHP: Select all

 <?
  
//database connectivity include
  
include "../includes/dbinfo_test.inc.php";
  include 
"includes/adminheader.inc.php";
  
?>
  
  <?
 
   
switch ($_GET['action']) {
     case 
"edit":
       
$authorsql "SELECT * FROM author WHERE authorid = '" $_GET['id'] . "'";
       
$result mysql_query($authorsql) or die("Invalid query: " mysql_error());
       
$row mysql_fetch_array($result);
       
$author_name $row['authorname'];
       break;
   }
 
?>
 <html>
 <head>
 <title><?php echo $_GET['action']; ?> author</title>
  <style type="text/css">
 <!--
 @import url("../css/stylesadmin.css");
 -->
  </style>
 </head>
 <body>
 <div id="Content">
   <form action=".././admin/commit_authors.php?action=<?php
   
echo $_GET['action']; ?>&type=author&id=<?php
   
if (isset($_GET['id'])) { echo $_GET['id']; } ?>" method="post">
 <?php
 
if (!empty($_GET['error'])) {
   echo 
"<div align=\"center\" " .
        
"style=\"color:#FFFFFF;background-color:#FF0000;" .
        
"font-weight:bold\">" nl2br(urldecode($_GET['error'])) . 
        
"</div><br />";    
 }
 
?>
     <table border="0" width="500" cellpadding="3"
       cellspacing="1" bgcolor="#353535" class="style1">
       <tr>
         <td bgcolor="#FFFFFF" width="33%"><p><strong>Author(s) Name(s):</strong><br />
         </p></td>
         <td bgcolor="#FFFFFF" width="67%">
           <input name="author_name" type="text"
             value="<?php echo $author_name?>" size="46"></td>
       </tr>
       <tr>
         <td bgcolor="#FFFFFF" width="33%"></td>
         <td bgcolor="#FFFFFF" width="67%">
           <input type="submit" name="SUBMIT" value="<?php echo $_GET['action']; ?>"></td>
       </tr>
     </table>
 </form>
 </div>
 </body>
 </html>
Many thanks in advance...
Reply With Quote

  #2 (permalink)  
Old Nov 3rd, 2005, 16:05
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
Re: header not redirecting

what error do you get when trying to redirect?
if you have so much as a space before your opening php tag it wont let you use a header....
Reply With Quote
  #3 (permalink)  
Old Nov 3rd, 2005, 16:12
New Member
Join Date: Nov 2005
Location: U.K
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pilch Send a message via MSN to pilch Send a message via Skype™ to pilch
Re: header not redirecting

Quote:
Originally Posted by benbacardi
what error do you get when trying to redirect?
if you have so much as a space before your opening php tag it wont let you use a header....
no error bbc
Reply With Quote
  #4 (permalink)  
Old Nov 4th, 2005, 00:29
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: header not redirecting

Quote:
Originally Posted by benbacardi
if you have so much as a space before your opening php tag it wont let you use a header....
Indeed ... and the sample code you're sending out has already sent out some style information before the header function is called which is your problem.

Looking wider, why redirect? Why not have the script you're working on generate the error output itself?
Reply With Quote
  #5 (permalink)  
Old Nov 7th, 2005, 20:24
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
Re: header not redirecting

I can understand the redirect - that way you can have many pages doing this, without having to rewrite code (although a function would do the same), but I agree - a bit convoluted this way.
Reply With Quote
Reply

Tags
header, redirecting

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Redirecting Monie Hosting & Domains 13 Jan 25th, 2008 00:54
[SOLVED] redirecting Anonymous User PHP Forum 1 Feb 7th, 2005 23:00
redirecting page.... Monie Classic ASP 18 Aug 19th, 2004 10:46
Redirecting Problem Amari Classic ASP 4 Aug 16th, 2004 17:17


All times are GMT. The time now is 18:45.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43