I have a page with php script to execute various 'actions' (to edit, add, delete and undelete records). At the end of the page I issue a header statment. The header works to readirect the page for all action except add. I read on another thread "there must be no output at all before invoking a header(). The <?php must be the very first line, and there must not be any extra spacebars in your script (like at the end of a line before the carriage return) before the header() function."
I checked my code for this and just can't figure out why it works for 3 of my 'actions' but not for 'add'. Is there anything in the ADD section of this code that would mess up the header() command? I'm pulling my hair out. Sorry the code is so long.
Thanks so much
<?php require_once('../Connections/setsoproject.php'); ?>
<?
#get URL variables
$action=$GET['action'];
$ngo_id=$POST['ngo_id'];
?>
<?php
#FOR EDIT
if ($action=="edit") {
if ($POST['deletechoice']=="") {
$status=1;
} else {
$status=$POST['deletechoice'];
}
#update record for this ngo in ngo table
$sql=" UPDATE ngo SET ngo_name='".$POST['ngo_name']."',ngo_alias='".$POST['ngo_alias']."',ngo_tagline='".$POST['ngo_tagline']."',ngo_mission='".$POST['ngo_mission']."',ngo_programs_full='".$POST['ngo_programs_full']."',ngo_programs='".$POST['ngo_programs']."',ngo_budget='".$POST['ngo_budget']."',ngo_nstaff='".$POST['ngo_nstaff']."',ngo_usedonate='".$POST['ngo_usedonate']."',ngo_goals='".$POST['ngo_goals']."',ngo_foundedyr='".$POST['ngo_foundedyr']."',ngo_opport='".$POST['ngo_opport']."',ngo_director='".$POST['ngo_director']."',ngo_website='".$POST['ngo_website']."',ngo_phone='".$POST['ngo_phone']."',ngo_fax='".$POST['ngo_fax']."',ngo_email='".$POST['ngo_email']."',ngo_add1='".$POST['ngo_add1']."',ngo_add2='".$POST['ngo_add2']."',ngo_city='".$POST['ngo_city']."',ngo_zip='".$POST['ngo_zip']."',status='".$status."' WHERE ngo_id=".$ngo_id;
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
?>
<?php
#delete all focus words for this ngo then reinsert the new ones
#delete
$sql=" DELETE from focusngo WHERE ngo_id=".$ngo_id;
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
#insert new ones
$foci=$POST['foci'];
$sql=" INSERT into focusngo (ngo_id,focus_id,status) values ";
$i=0;
while($foci[$i]!="") {
if ($i==0) {
$sql.="('".$ngo_id."','".$foci[$i]."',1)";
} else {
$sql.=",('".$ngo_id."','".$foci[$i]."',1)";
}
$i++;
}
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
?>
<?php
#delete all countries for this ngo then reinsert the new ones
#delete
$sql=" DELETE from countryngo WHERE ngo_id=".$ngo_id;
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
#insert new ones
$foci=$POST['cntry'];
$sql=" INSERT into countryngo (ngo_id,country_id,status) values ";
$i=0;
while($cntry[$i]!="") {
if ($i==0) {
$sql.="('".$ngo_id."','".$cntry[$i]."',1)";
} else {
$sql.=",('".$ngo_id."','".$cntry[$i]."',1)";
}
$i++;
}
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
}
#END EDIT SECTION
?>
<?php
#FOR ADD
if ($action=="add") {
#insert new record in table ngo
$sql=" INSERT into ngo ";
$sql.="(ngo_name,ngo_alias,ngo_tagline,ngo_mission,ngo_programs_full,ngo_programs,ngo_budget,ngo_nstaff,ngo_usedonate,ngo_goals,ngo_foundedyr,ngo_opport,ngo_director,ngo_website,ngo_phone,ngo_fax,ngo_email,ngo_add1,ngo_add2,ngo_city,ngo_zip,status)";
$sql.=" values ('".$POST['ngo_name']."','".$POST['ngo_alias']."','".$POST['ngo_tagline']."','".$POST['ngo_mission']."','".$POST['ngo_programs_full']."','".$POST['ngo_programs']."','".$POST['ngo_budget']."','".$POST['ngo_nstaff']."','".$POST['ngo_usedonate']."','".$POST['ngo_goals']."','".$POST['ngo_foundedyr']."','".$POST['ngo_opport']."','".$POST['ngo_director']."','".$POST['ngo_website']."','".$POST['ngo_phone']."','".$POST['ngo_fax']."','".$POST['ngo_email']."','".$POST['ngo_add1']."','".$POST['ngo_add2']."','".$POST['ngo_city']."','".$POST['ngo_zip']."','9')";
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
?>
<?php
#now get the id for this new record;
mysql_select_db($database_setsoproject, $setsoproject);
$query_justadded = "SELECT ngo_id FROM ngo WHERE status = 9";
$justadded = mysql_query($query_justadded, $setsoproject) or die(mysql_error());
$row_justadded = mysql_fetch_assoc($justadded);
$totalRows_justadded = mysql_num_rows($justadded);
$ngo_id=$row_justadded['ngo_id'];
?>
<?php
#insert each chosen focus word into focusngo table
$foci=$POST['foci'];
$sql=" INSERT into focusngo (ngo_id,focus_id,status) values ";
$i=0;
while($foci[$i]!="") {
if ($i==0) {
$sql.="('".$ngo_id."','".$foci[$i]."',1)";
} else {
$sql.=",('".$ngo_id."','".$foci[$i]."',1)";
}
$i++;
}
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
?>
<?php
#insert each chosen country word into countryngo table
$cntry=$POST['cntry'];
$sql=" INSERT into countryngo (ngo_id,country_id,status) values ";
$j=0;
while($cntry[$j]!="") {
if ($j==0) {
$sql.="('".$ngo_id."','".$cntry[$j]."',1)";
} else {
$sql.=",('".$ngo_id."','".$cntry[$j]."',1)";
}
$j++;
}
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
?>
<?php
#set the status of the new ngo to 1 in ngo table
$sql=" UPDATE ngo SET status='1' WHERE ngo_id=".$ngo_id;
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
mysql_free_result($justadded);
}
#END OF ADD SECTION
?>
<?php
#FOR DELETE
if ($action=="delete") {
$sql=" UPDATE ngo SET status='0' WHERE ngo_id=".$GET['ngo_id'];
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die("delete Failed<br>".$sql);
}
?>
<?php
#FOR UNDELETE
if ($action=="undelete") {
$sql=" UPDATE ngo SET status='1' WHERE ngo_id=".$GET['ngo_id'];
mysql_select_db($database_setsoproject, $setsoproject);
$Result = mysql_query($sql, $setsoproject) or die(mysql_error());
}
?>
<?php
header("Location: http://www.setsoproject.org/admin/list_ngo.php"); / Redirect browser /
echo "if you are not automatically redirected, click <a href='http://www.setsoproject.org/admin/list_ngo.php'>here<a>";
exit;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>