Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/240027-script-auto-redirects/
Share on other sites

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

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 :D

Thanx!

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.