Having trouble with header redirection passing variables from the url.

<? ob_start(); ?>
require_once ("Includes/config.php"); 
require_once  ("Includes/connectDB.php");
$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);

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)
echo "Failed deleting Article";
<?php include ("Includes/footer.php");?>
<? ob_flush(); ?>

Recommended Answers

All 10 Replies

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


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.


which then deletes the record and should redirect back to.


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, learning, and sharing knowledge.