takn25 Posted March 9, 2011 Share Posted March 9, 2011 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! Quote Link to comment Share on other sites More sharing options...
btherl Posted March 9, 2011 Share Posted March 9, 2011 What did you try with header? Quote Link to comment Share on other sites More sharing options...
takn25 Posted March 9, 2011 Author Share Posted March 9, 2011 $getid=$_GET['id']; Tried some thing like header(LOCATION: http://localhost/page/profile.php?id=$getid); No luck Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 9, 2011 Share Posted March 9, 2011 Please show us your code Quote Link to comment Share on other sites More sharing options...
takn25 Posted March 10, 2011 Author Share Posted March 10, 2011 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? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 10, 2011 Share Posted March 10, 2011 Do you fetch the data before or after updating it? Quote Link to comment Share on other sites More sharing options...
takn25 Posted March 10, 2011 Author Share Posted March 10, 2011 I am fetching it before the update and what I had in mind if the page refreshes should it not fetch again? Quote Link to comment Share on other sites More sharing options...
takn25 Posted March 10, 2011 Author Share Posted March 10, 2011 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> Quote Link to comment Share on other sites More sharing options...
takn25 Posted March 10, 2011 Author Share Posted March 10, 2011 I echoed this just to see whats going on "data was posted and page refreshed" and I am recieving this msg but the fetched data is not refreshing. Quote Link to comment Share on other sites More sharing options...
takn25 Posted March 10, 2011 Author Share Posted March 10, 2011 Just a question? Could it be because I am testing this on Localhost and if it was Online maybe the page refreshes in a different manner and the data Refreshes with it? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 10, 2011 Share Posted March 10, 2011 I can see your code there .. but how are you refreshing? Are you using a meta tag to refresh? Another method is using header("Location: ") Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 10, 2011 Share Posted March 10, 2011 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 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.