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!
When Checking for the Validity of user and valid != "yes" i get this error:
Warning: Cannot modify header information - headers already sent by (output started at c:\apache group\apache\htdocs\inventory\do_delrecord.php:3) in c:\apache group\apache\htdocs\inventory\do_delrecord.php on line 4
<?
//check for required form variables
if (!$_POST['user_name']) {
header("Location:http://byron/inventory/pick_delrecord.php");
exit;
} else {
//if form variables are present,start a session
session_start();
}
//check for validity of user
if ($_SESSION['valid'] != "yes") {
header("Location:http://byron/inventory/inventory_menu.php");
exit;
}
?>
<?php<? if ($_SESSION['valid'] != "yes") {
header("Location:http://byron/inventory/inventory_menu.php");
exit;
}
//check for required form variables
if (!$_POST['user_name']) {
header("Location:http://byron/inventory/pick_delrecord.php");
exit;
} else {
//if form variables are present,start a session
session_start();
}
//set up table and database names
$db_name ="Inventory";
$table_name ="client_hardware";
//connect to server and select database
$connection =@mysql_connect("localhost","byron","byronb") or die(mysql_error());
$db =@mysql_select_db($db_name,$connection) or die(mysql_error());
//build and issue query
$sql = "DELETE FROM $table_name WHERE user_id ='".$_POST['user_id']."'";
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<HTML>
<HEAD>
<TITLE>Inventory Management System: Record Deleted</TITLE>
</HEAD>
<BODY bgcolor="B1D3EC">
<h2><em>Delete a Record - Record Deleted</em></h2>
<P><? echo "$_POST[user_name] $_POST[user_id]"; ?> has been deleted from <? echo "$table_name"; ?></p>
<br><p><a href="inventory_menu.php">Return to Main Menu</a></p>
</BODY>
</HTML>
?>
I changed the top two around and still get the errors.. I have no spaces before <? and i get this:
Notice: Undefined variable: _SESSION in c:\apache group\apache\htdocs\inventory\do_delrecord.php on line 1
Warning: Cannot modify header information - headers already sent by (output started at c:\apache group\apache\htdocs\inventory\do_delrecord.php:1) in c:\apache group\apache\htdocs\inventory\do_delrecord.php on line 2
I guess the header problem has already been solved.
But because your $_SESSION["valid"] is not defined. It shows error message which makes PHP parse out some content before the header is sent out.