0

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(); ?>

Edited by mark.giles.14: code

3
Contributors
10
Replies
29
Views
3 Years
Discussion Span
Last Post by mark.giles.14
0

URL

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

Edited by mark.giles.14

0

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.

Edited by tapananand

0

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.

0

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

0

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

Edited by tapananand

0

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.

Edited by tapananand

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.