eightFX Posted July 10, 2007 Share Posted July 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 <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? Quote Link to comment Share on other sites More sharing options...
eightFX Posted July 10, 2007 Author Share Posted July 10, 2007 It was my assumption that meta tags needed to be in between <head> tags, is that not so? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 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; ?> Quote Link to comment Share on other sites More sharing options...
eightFX Posted July 10, 2007 Author Share Posted July 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 <?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. Quote Link to comment Share on other sites More sharing options...
eightFX Posted July 10, 2007 Author Share Posted July 10, 2007 Works like a charm! Did not even think to use javascript, got so wrapped up in coding in php. Thanks again Frost! Kudos! Quote Link to comment Share on other sites More sharing options...
eightFX Posted July 10, 2007 Author Share Posted July 10, 2007 Frost, is there a way I can still pass a value to the root page saying "Successful" so users dont think they just clicked on something wrong? Quote Link to comment Share on other sites More sharing options...
per1os Posted July 10, 2007 Share Posted July 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
eightFX Posted July 10, 2007 Author Share Posted July 10, 2007 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.