Having trouble with header redirection passing variables from the url.

<? ob_start(); ?>
<?php 
require_once ("Includes/config.php"); 
require_once  ("Includes/connectDB.php");
include("Includes/header.php"); 
confirm_is_admin();
$lid = $_GET['lid'];
$yr = $_GET['yr'];
$gid = $_GET['gid'];
$pid = $_GET['pid'];
$pn = $_GET['pn'];

if (is_admin())
{
$aid = $_GET['aid'];
$query = "DELETE FROM articles WHERE article_id = ?";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('i', $aid);
$statement->execute();
$statement->store_result();

if ($statement->error)
{
die('Database query failed: ' . $statement->error);
}
// TODO: Check for == 1 instead of > 0 when State names become unique.
$deletionWasSuccessful = $statement->affected_rows > 0 ? true : false;
if ($deletionWasSuccessful)
{
header("Location:articlelist.php?lid=$league_id&yr=$season&gid=$gid&pid=$pid&pn=$pn");
}
else
{
echo "Failed deleting Article";
}
}
else
{
header("Location:articlelist.php?lid=$lid&yr=$yr&gid=$gid&pid=$pid&pn=$pn");
}
?>
<?php include ("Includes/footer.php");?>
<? ob_flush(); ?>

What is the name of the page form where the data is to be passed, clarify the context clearly.

From where you are getting a value for $league_id and $season

URL

Sorry they should actually be lid & yr. just never changed them in the code I pasted.

Try replacing the line: header("Location:articlelist.php?lid=$league_id&yr=$season&gid=$gid&pid=$pid&pn=$pn");
With this: echo "<script type=\"text/javascript\">window.location.href=\'articlelist.php?lid=".$league_id."&yr=".$season."&gid=".$gid."&pid=".$pid."&pn=".$pn."\'</script>";
and similarly in the else part as well.
Change the variable names to the correct ones in my code as well ofcourse.

As an example to get to the page I would use.

deletearticle.php?aid=8&lid=&yr=2014&gid=&pid=1&pn=0

which then deletes the record and should redirect back to.

articlelist.php?lid=$lid&yr=$yr&gid=$gid&pid=$pid&pn=$pn

If that makes sense.

Thanks Tap, but that didnt work just got a white screen and froze at deletearticle.php.

See the generated source code now or may be paste it here(just the important part). Don't forget to use semicolon after echo.

Sorry wrongly posted it should be: echo "<script type=\"text/javascript\">window.location.href='articlelist.php?lid=".$league_id."&yr=".$season."&gid=".$gid."&pid=".$pid."&pn=".$pn."'</script>";
i.e. replace \' by ' only.

Thanks tap. it worked perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.