header error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

header error

Post by dsjoes »

the script below works but i have started getting this error
Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php:10) in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php on line 95
line 95 is this bit

Code: Select all

header('Location: index.php');

Code: Select all

<?php
// Set Global Vars
$HOST = "xxxxxxxxxx";
$USERNAME = "xxxxxxxxx";
$PASSWORD = "xxxxxxxxx";
$DATABASE = "group";
$TABLE = "Testimonials";
// Establish a connection
mysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());
//==================================================================
// Check if anything is posted
//==================================================================
if (isset($_POST['delete'])) {
    $sql = ("delete from $TABLE where ");
    for ($i = 0; $i < count($_POST['checkbox']); $i++) {
        if ($i != 0) {
            $sql.= "OR ";
        }
        $sql .= " id='" . $_POST['checkbox'][$i] . "'";
        //==================================================================
        // Select file to unlink based on id posted
        //==================================================================
        $sql_file_unlink = "select Download from $TABLE where id = {$_POST['checkbox'][$i]}";
        $result_file_unlink =  mysql_query($sql_file_unlink);
        $row_file_link = mysql_fetch_assoc($result_file_unlink);
        if($row_file_link) {
             unlink('../testimonial_files/' . $row_file_link['Download']);
        }
        //==================================================================
    }
    $result = mysql_query($sql);
    header('Location: index.php');
    exit;
} else {
    // select sql here
    $sql = "select * from `$TABLE` order by `id`;";
    $result = mysql_query($sql);
}
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
     <tr>
      <td colspan="6" align="center"><strong>Testimonials</strong> </td>
    </tr>
    <tr>
        <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
                <table width="400" border="1" cellpadding="3" cellspacing="1">
                    <tr>
                        <td align="center"><strong>Select</strong></td>
                        <td align="center"><strong>ID</strong></td>
                        <td align="center"><strong>Name</strong></td>
                        <td align="center"><strong>Description</strong></td>
                        <td align="center"><strong>Download</strong></td>
                        <td align="center"><strong>Last Modified</strong></td>
                    </tr>
                    <?php $row = mysql_fetch_assoc($result); ?><?php do { ?>
                        <tr>
                            <td align="center">
                                <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">
                            </td>
                            <td align="center"><?php echo $row['id']; ?></td>
                            <td align="center"><?php echo $row['Name']; ?></td>
                            <td align="center"><?php echo $row['Message']; ?></td>
                            <td align="center"><a href="../testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>
                            <td align="center"><?php echo date("j/n/y", strtotime($row["Modified"])) ?></td>
                        </tr>
                      <?php
                      } while ($row = mysql_fetch_assoc($result)); ?>
                        <tr>
                            <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
    </table>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: header error

Post by requinix »

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php:10) in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php on line 95
Find out why there was output and get rid of it. You can't use functions like header() if PHP has outputted anything.
Peec
Forum Commoner
Posts: 33
Joined: Fri Feb 22, 2008 3:58 am

Re: header error

Post by Peec »

This means that you have outputted something before the header() function tries to redirect.
Line 10 in index.php is causing it, it can be everything from a single space to a PHP warning / notice /error that outputs content.
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: header error

Post by dsjoes »

thanks i have checked my script on its own and it works ok and the line ten is my style sheet so i will move things around until it works thanks :D
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: header error

Post by dsjoes »

EDIT
fixed it
Post Reply