Jump to content

[SOLVED] REDIRECT AFTER SUCCESS


eightFX

Recommended Posts

Hello All!

 

I am looking to redirect a user to another page after successful update/insert into the database. I was using the meta tag but I only want it to redirect automatically if the update/insert was successful. This is the basics of what I have:

 

CURRENT URL WOULD BE: MYSITE.COM/?entry=1

 

<head><META HTTP-EQUIV=REFRESH CONTENT="5;URL=../"></head>
<body>
<?

if ($_GET['entry'] ==1) {

$query = "UPDATE table SET id='$id', name='$name', content='$content' WHERE id='$id'"

$r = mysql_query ($query);

if (mysql_affected_rows() == 1) {
	print 'information has been updated.'; // I WANT THE REFRESH TO HAPPEN HERE
} else {
	print "could not update the entry because: <b>" . mysql_error() . "</b>. The query was $query."; // I DO NOT WANT THE REFRESH HERE
}

}
?>

</body>

 

Any help would be great not sure if anyone has tried to do this or not I could not find anything in search.

Link to comment
https://forums.phpfreaks.com/topic/59277-solved-redirect-after-success/
Share on other sites

<head></head>
<body>
<?php

if ($_GET['entry'] ==1) {

$query = "UPDATE table SET id='$id', name='$name', content='$content' WHERE id='$id'"

$r = mysql_query ($query);

if (mysql_affected_rows() == 1) {
	print '<META HTTP-EQUIV=REFRESH CONTENT="5;URL=../">'; // I WANT THE REFRESH TO HAPPEN HERE
} else {
	print "could not update the entry because: <b>" . mysql_error() . "</b>. The query was $query."; // I DO NOT WANT THE REFRESH HERE
}

}
?>

 

Would that not work?

HTML is very lienant and forgiving. Unless you are going for standards it really doesn't matter where it is. But if you are this would work too.

 

<?php

if ($_GET['entry'] ==1) {

$query = "UPDATE table SET id='$id', name='$name', content='$content' WHERE id='$id'"

$r = mysql_query ($query);
        $meta = "";
if (mysql_affected_rows() == 1) {
	$meta = '<META HTTP-EQUIV=REFRESH CONTENT="5;URL=../">'; // I WANT THE REFRESH TO HAPPEN HERE
                $output = 'Wait a few moments while I redirect you.';
} else {
	$output = "could not update the entry because: <b>" . mysql_error() . "</b>. The query was $query."; // I DO NOT WANT THE REFRESH HERE
}

}
?>
<head><?php echo $meta; ?></head>
<body>
<?php echo $output; ?>

Thanks Frost, that second post makes sense. Unfortunately that does not seem to be working for me and I think I know why, the page that this takes place in is included on a different page, and therefore comes after the head tag is already closed and is in the body of the page. I wish I could somehow change the URL after the the update is complete because then I could use the variables in the URL, I just can't seem to figure out how to get that to happen.

<?php

if ($_GET['entry'] ==1) {

$query = "UPDATE table SET id='$id', name='$name', content='$content' WHERE id='$id'"

$r = mysql_query ($query);

if (mysql_affected_rows() == 1) {
	print '<script type=text/javascript>window.location=\'../\';</script>'; // I WANT THE REFRESH TO HAPPEN HERE
} else {
	print "could not update the entry because: <b>" . mysql_error() . "</b>. The query was $query."; // I DO NOT WANT THE REFRESH HERE
}

}
?>

 

Try a javascript redirect.

What I would do is redirect them to a "success.php" page or a "thankyou.php" page, which has a meta redirect on it and a message.

 

That way if you used POST it clears that data for "back" button safe browsing and it eliminates the chance of double entries. But thats just me.

Archived

This topic is now archived and is closed to further replies.

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