-1

So, I am currently on a page.

adminpanel.php?type=pdetail&id=1&op=edit

each of my variables create a some part of my page by echoing out HTML tags. I want my page to redirect to

adminpanel.php?type=edit

(my type variable was already defined as "pdetail" I want it to modified to "edit")

if($op == 'edit')
{
    $id = $_GET['id'];
    echo("Testing IF condition");
    header("location:adminpanel.php?type=edit");
}
Daniyal Nasir
  • 669
  • 7
  • 22
  • you're outputting before header right now; remove the echo statement. Error reporting will tell you that http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner May 27 '15 at 15:50

1 Answers1

1

As I mentioned in comments, you're outputting before headers (see "References" below). There should not be any output before that, including one or more spaces before the opening <?php tag, HTML, cookies, etc., or anything that would cause an error.

This is covered in the link I have provided for you below, under "References".

  • Remove the "echo" statement.

Whether you saw my comment or not is unknownst to me, and am submitting the following answer.

If error reporting were set/on on your server, you would be receiving a warning similar to this:

Warning: Cannot modify header information - headers already sent by (output started at /var/user/you/folder/adminpanel.php:12) in /var/user/you/folder/adminpanel.php on line x

Tested with the following and added some code that you left out in your question, proved to be successful.

<?php 
$op = $_GET['op'];

    if($op == 'edit')
    {
        $id = $_GET['id'];
        header("location:adminpanel.php?type=edit");
        exit;
    }

Sidenote: It's best to add exit; after header, should there be more code following that. Otherwise, your code may want to continue executing.


References:


Error reporting:

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141