adam291086 Posted December 13, 2007 Share Posted December 13, 2007 i am trying to run a script that carrys out two function depending on a variable state. The delete part works but when the header is supposed to chage nothing happens. Can anyone see why <?php include '../database/config.php'; $delete = $_POST['delete']; $edit = $_post['edit']; if (!empty($delete)) { mysql_query("DELETE FROM News WHERE news_id='$delete'"); if (!mysql_query) { echo "not deleted"; } else { echo "Deleted"; } } elseif (!empty($edit)) { header('Location: http://cycloxchamps.co.uk/rte/rte.php?news='.urlencode($edit).''); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/ Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 try <?php include '../database/config.php'; $delete = $_POST['delete']; $edit = $_post['edit']; if (!empty($delete)) { mysql_query("DELETE FROM News WHERE news_id='$delete'"); if (!mysql_query) { echo "not deleted"; } else { echo "Deleted"; } } if (!empty($edit)) { header('Location: http://cycloxchamps.co.uk/rte/rte.php?news='.urlencode($edit).''); } Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414304 Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 still nothing ??? Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414309 Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 still nothing ??? change $edit = $_post['edit']; to $edit = $_POST['edit']; Always capitals my friend. Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414312 Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 oopss after adding error (e_all) i get the errors Notice: Undefined index: delete in /homepages/30/d227915861/htdocs/news/modifynews.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /homepages/30/d227915861/htdocs/news/modifynews.php:4) in /homepages/30/d227915861/htdocs/news/modifynews.php on line 28 I am try to say if delete is ticked then delete or if edit is ticked then header location what am i doing wrong <?php error_reporting(E_ALL); include '../database/config.php'; $delete = $_POST['delete']; $edit = $_POST['edit']; if (!empty($delete)) { $result = mysql_query("DELETE FROM News WHERE news_id='$delete'"); if ($result) { echo "deleted"; } else { echo " not Deleted"; } } if (!empty($edit)) { header('Location: http://www.google.com'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414322 Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 header(); must come before ANY HTML on the page. Check the config.php page for any HTML that gets echo'ed or printed. Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414330 Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 config is just the mysql connect. Therefore only contains my username ect ect Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414334 Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 config is just the mysql connect. Therefore only contains my username ect ect Post the full script/code for the modifynews.php page Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414337 Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 this is for the modifynew <?php error_reporting(E_ALL); include '../database/config.php'; $delete = $_POST['delete']; $edit = $_POST['edit']; if (!empty($delete)) { $result = mysql_query("DELETE FROM News WHERE news_id='$delete'"); if ($result) { echo "deleted"; } else { echo " not Deleted"; } } if (!empty($edit)) { header('Location: http://www.google.com'); } ?> this is for the news.php where the variables are sent from <?php include '../database/config.php'; echo '<form action="modifynews.php" method="post">'; $result = mysql_query("SELECT * FROM News") or die(mysql_error()); while($row = mysql_fetch_array($result)) { $id = $row['news_id']; $title = $row['News_title']; $news = $row['News']; $adam = substr($news, 0, 50); echo "<br />"; echo $title; echo "<br />"; echo $adam; echo "<br />"; echo '<a href="http://cycloxchamps.co.uk/news/shownews.php?news='.urlencode($id).'">'. $id.'</a>'; echo '<br />'; echo '<input type="radio" name="delete" value="'.$id.'" />Delete '; echo '<br />'; echo '<input type="radio" name="edit" value="'.$id.'" />Edit '; echo '<br />'; echo '<input type="submit" value="Delete Selected">'; } include '../database/closedb.php'; Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414342 Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Why was i so blind. Think this will work <?php error_reporting(E_ALL); include '../database/config.php'; $delete = $_POST['delete']; $edit = $_POST['edit']; if (!empty($edit)) { header('Location: http://www.google.com'); } if (!empty($delete)) { $result = mysql_query("DELETE FROM News WHERE news_id='$delete'"); if ($result) { echo "deleted"; } else { echo " not Deleted"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414345 Share on other sites More sharing options...
adam291086 Posted December 13, 2007 Author Share Posted December 13, 2007 throws the errors Notice: Undefined index: delete in /homepages/30/d227915861/htdocs/news/modifynews.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /homepages/30/d227915861/htdocs/news/modifynews.php:4) in /homepages/30/d227915861/htdocs/news/modifynews.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414347 Share on other sites More sharing options...
trq Posted December 13, 2007 Share Posted December 13, 2007 Check your files have no whitespace outside of the <?php ?> tags. Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414350 Share on other sites More sharing options...
phpSensei Posted December 13, 2007 Share Posted December 13, 2007 Do what thorpe said, and try <?php $edit = $_POST['edit']; if (!empty($edit)) { header('Location: http://www.google.com'); } error_reporting(E_ALL); include '../database/config.php'; $delete = $_POST['delete']; if (!empty($delete)) { $result = mysql_query("DELETE FROM News WHERE news_id='$delete'"); if ($result) { echo "deleted"; } else { echo " not Deleted"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414354 Share on other sites More sharing options...
adam291086 Posted December 14, 2007 Author Share Posted December 14, 2007 Works well. Thanks for the help guys. Quote Link to comment https://forums.phpfreaks.com/topic/81583-solved-header-location/#findComment-414728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.