Jump to content

[SOLVED] header location


adam291086

Recommended Posts

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).'');
}





?>

Link to comment
https://forums.phpfreaks.com/topic/81583-solved-header-location/
Share on other sites

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).'');
}

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');
}
?>

 

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';

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";
    }
   
}


?>

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

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";
    }
   
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.