i dont know why i am having an error in header

Warning: Cannot modify header information - headers already sent by (output started at delete.php on line 13

delete.php

<?php


  include("db.php");  

	$id =$_REQUEST['BookID'];
	
	
	// sending query
	mysql_query("DELETE FROM books WHERE BookID = '$id'")
	or die(mysql_error());  	
	
	header("Location: index.php");

?>

db.php

<?php  
	$conn = mysql_connect('localhost', 'root', '');
	 if (!$conn)
    {
	 die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("Books", $conn);
?>

:)

Recommended Answers

All 4 Replies

i have error in line 28

view.php

<?php
require("db.php");
$id =$_REQUEST['BookID'];

$result = mysql_query("SELECT * FROM books WHERE BookID  = '$id'");
$test = mysql_fetch_array($result);
if (!$result)
		{
		die("Error: Data not found..");
		}
				$Title=$test['Title'] ;
				$Author= $test['Author'] ;					
				$PublisherName=$test['PublisherName'] ;
				$CopyrightYear=$test['CopyrightYear'] ;

if(isset($_POST['save']))
{
	$title_save = $_POST['title'];
	$author_save = $_POST['author'];
	$name_save = $_POST['name'];
	$copy_save = $_POST['copy'];

	mysql_query("UPDATE books SET Title ='$title_save', Author ='$author_save',
		 PublisherName ='$name_save',CopyrightYear ='$copy_save' WHERE BookID = '$id'")
				or die(mysql_error()); 
	echo "Saved!";

	header("Location: index.php");
}
mysql_close($conn);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="post">
<table>
	<tr>
		<td>Title:</td>
		<td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
	</tr>
	<tr>
		<td>Author</td>
		<td><input type="text" name="author" value="<?php echo $Author ?>"/></td>
	</tr>
	<tr>
		<td>Publisher Name</td>
		<td><input type="text" name="name" value="<?php echo $PublisherName ?>"/></td>
	</tr>
	<tr>
		<td>Copyright Year</td>
		<td><input type="text" name="copy" value="<?php echo $CopyrightYear ?>"/></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" name="save" value="save" /></td>
	</tr>
</table>

</body>
</html>

i have an error in line 28.

Member Avatar for diafol

Obviously - you've echoed 'Saved'.

Re-read my last post.

use ob_start(); after the <?php at the very first php code and ob_flush(); before the the end tag ?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.