maximeke2 Posted June 21, 2011 Share Posted June 21, 2011 Hi everybody, i'm working on a event page, and registered users can comment on the events. If they posted a comment before, they can edit that comment by clicking a link. Once you're in that link, you can edit the title & the content. So when they press submit, the scripts checks your information and updates the database. Now comes the strange part... my scripts redirects automatically back to the previous page, shows the $_SESSION['msg'] var and doesn't update my database.. I should normally stay on that page and not go back.. <?php session_start(); if(!session_is_registered(username)) { echo "<script>history.back()</script>"; } if($_GET['id'] == '') { echo "<script>history.back()</script>"; } ?> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <script src="scripts/jquery-1.2.6.min.js"></script> <link href="styleff.css" rel="stylesheet" type="text/css"> <title>Events</title> <?php include 'begin.php'; ?> <div id="contentpage"> <center><h1>Events</h1></center> <?php $id=$_GET['id']; list($rightname) = mysql_fetch_row(mysql_query("select username from eventsresponse where id='$id'")); if($rightname != $_SESSION['username'] && $_SESSION['rank'] < '5') { $_SESSION['msg']='You don\'t have the permission to do that'; echo "<script>history.back()</script>"; } $discr=$_POST['discr']; $discr = stripslashes($discr); $discr = str_replace(' ',' ',$discr); $title = $_POST['title']; $title = stripslashes($title); $title = str_replace(' ',' ',$title); mysql_query("UPDATE eventsresponse SET title = '$title' WHERE id='$id'"); $_SESSION['msg']='Saved!'; ?> any help would be welcome :-\ maximeke2 Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/ Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 The function session_is_registered() is deprecated Try instead. if($_SESSION['username'] Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1232966 Share on other sites More sharing options...
maximeke2 Posted June 21, 2011 Author Share Posted June 21, 2011 Edited but it still redirects Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1232971 Share on other sites More sharing options...
fugix Posted June 21, 2011 Share Posted June 21, 2011 if($rightname != $_SESSION['username'] && $_SESSION['rank'] < '5') { $_SESSION['msg']='You don\'t have the permission to do that'; echo "<script>history.back()</script>"; } seems that upon loading this page, one of these conditions is being met to store the session and direct back Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1232990 Share on other sites More sharing options...
maximeke2 Posted June 21, 2011 Author Share Posted June 21, 2011 I'll try that tomorrow,now i'm going to bed Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1233023 Share on other sites More sharing options...
maximeke2 Posted June 22, 2011 Author Share Posted June 22, 2011 yes, $_SESION['msg'] is used to display a message, in the main file there is a script: <?php if($_SESSION['msg'] != '') { echo '<div id="message">'.$_SESSION['msg'].'</div><br>'; /* jquery part: */ ?> <script> $("#message").hide(); $("#message").show("slow"); $("#message").delay(3500).hide("slow"); </script> <? $_SESSION['msg']=''; } ?> But.. i deleted all the echo "<script>history.back()</script>"; and i placed them back one by one, and there's something wrong with this one: if($_GET['id'] == '') { echo "<script>history.back()</script>"; } if i place this one back, he redirects, even if the statement is false. EDIT: I figured it out! On the previous page there was a form, on wich i forgot to add the ?id=<? echo $id; ?>.. So it works now Thanx! Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1233243 Share on other sites More sharing options...
fugix Posted June 22, 2011 Share Posted June 22, 2011 I would advise to always use long tags. <?php instead of short tags. <? To avoid php.ini setting issues on your server. Just a quick tip Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1233394 Share on other sites More sharing options...
maximeke2 Posted June 22, 2011 Author Share Posted June 22, 2011 ok, i'll try it next time Quote Link to comment https://forums.phpfreaks.com/topic/240027-script-auto-redirects/#findComment-1233410 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.