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
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

That's why you are the super guru and I am a measly regular. I will try that, it makes more sense that way anyhow, because I can use "success" page multiple places and will not have to change code. Thanks again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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