database header

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

database header

Post by dsjoes »

i get these errors when try to delete from my sql database
[text]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 89

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php on line 105[/text]

this is the script that i am having the problem with

Code: Select all

<?php
$host="host"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="group"; // Database name 
$tbl_name="docs"; // Table name 
       

        // Connect to server and select databse.
        mysql_connect("$host", "$username", "$password")or die("cannot connect");
        mysql_select_db("$db_name")or die("cannot select DB");
       
        // Build SQL query
        if(!isset($_POST['delete'])) $sql="SELECT * FROM $tbl_name ORDER BY id";
        else {
                $sql = "DELETE FROM $tbl_name WHERE";

                // add row id to where section
                for($i=0;$i<count($_POST['checkbox']);$i++){
                        if($i != 0) $sql.= "AND ";
                        $sql .= " id='" . $_POST['checkbox'][$i] . "'";
                }
     }

      $result = mysql_query($sql);
       if(isset($_POST['delete']))  header('Location: index.php'); // redirect
?>
<table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="400" border="1" cellpadding="3" cellspacing="1">
<tr>
<td colspan="6" align="center"><strong>Docs</strong> </td>
</tr>
<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 while($rows=mysql_fetch_array($result)){ ?>
        <tr>
                <td align="center">
                        <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>">
                </td>
                <td><? echo $rows['id']; ?></td>
                <td><? echo $rows['Name']; ?></td>
                <td><? echo $rows['Message']; ?></td>
                <td><a href="/admin/doc_files/<? echo $rows['Download']; ?>">Download</a></td>
                <td><? echo $rows['Modified']; ?></td>
        </tr>
        <tr>
        <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>
        </tr>
<?php  }
        mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
and these are the two lines it is referring to

Code: Select all

if(isset($_POST['delete']))  header('Location: index.php'); // redirect
?>


<?php while($rows=mysql_fetch_array($result)){ ?>

User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: database header

Post by Darhazer »

Code: Select all

 if(isset($_POST['delete']))  header('Location: index.php'); // redirect
Have to be

Code: Select all

 if(isset($_POST['delete'])) {
    header('Location: index.php'); // redirect
    exit;
}
And make sure there is no whitespace / empty line before <?php
dsjoes
Forum Commoner
Posts: 41
Joined: Thu May 20, 2010 3:15 pm

Re: database header

Post by dsjoes »

i get this message now
[text]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 90[/text]


line 90 is the middle line of this

Code: Select all

if(isset($_POST['delete'])) {
    header('Location: index.php'); // redirect
    exit;
}
Post Reply