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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.