Jump to content

Facing a problem with redirecting back


takn25

Recommended Posts

Hi, I have a form with a textarea the problem I am facing is the user is logged in and is on a page

http://localhost/page/profile.php?id=28 now what I want to do is after the data is inserted  I want them to be re directed back to http://localhost/page/profile.php?id=28 the same url. I tried a few things with header also tried making the form action $_SERVER['PHP_SELF'] but what happens with $_SERVER['PHP_SELF'] for some odd reason the page doesnt Reload untill I refresh the browser tried in a few browsers same result. Could some one help me with this much appreciated!

Link to comment
Share on other sites

Ya sure ok after trying a few more things to see if the data is being posted and its a refreshed page I found out data is posted and I get an echo of it being refreshed the problem is. I am retrieving data from mysql on the same page which doesnt seem to refresh unless I do it manually why is this?

Link to comment
Share on other sites

Its more of Inserting rather than Updating  heres the main code. Could the inserting be the issue?

 

<?php

session_start();

 

$myid=$_SESSION['id'];

$post=$_POST['post'];

$gr=$_POST['gr'];

$uid=$_GET['id'];

 

if (isset($post))

 

{

 

if (isset($gr))

 

  {

 

$con=mysql_connect('localhost','root','');

$db=mysql_select_db('grap');  

 

$postnow=mysql_query("INSERT INTO grap VALUES ('$uid','$myid','$gr','')");

 

echo "data was posted and page refreshed";

 

  }

 

 

 

}

 

?>

<html>

<head>

</head>

 

 

 

 

<body>

<form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'>

<fieldset id='gf'>

<input type='text' value='<?php $gr; ?>' name='gr'/>

<input type='submit' id='pg' value='Post' name='post' />

</fieldset>

</form>

</body>

</html>

Link to comment
Share on other sites

Perhaps (untested)...

<?php
session_start();
$myid=$_SESSION['id'];
$uid=$_GET['id'];
if(isset($_GET['id'])){
$uid = $_GET['id'];
}else{
if(isset($_POST['hidden_id'])) {
	$uid = $_POST['hidden_id'];
}else{
/* redirect as there is no value for $uid */
exit();
}	

if (isset($_POST['post']) AND isset($_POST['gr'])){
$con=mysql_connect('localhost','root','');
$db=mysql_select_db('grap');    
$postnow=mysql_query("INSERT INTO grap VALUES ('$uid','$myid','$gr','')");
echo "data was posted and page refreshed";   
}
?>
<html>
<head>
</head>
<body>
<form action="" method="POST">
<fieldset id="gf">
	<input type = "hidden" name = "hidden_id" value="<?PHP echo $uid; ?>">
	<input type= "text" value="<?php echo $gr; ?>" name="gr"/>
	<input type="submit" id="pg" value="Post" name="post" />
</fieldset>
</form>
</body>
</html>

Note: in this portion of code, you have not allowed user to go anywhere else.

Also, you need to sanitize your form data

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.