Eiolon Posted December 8, 2007 Share Posted December 8, 2007 When someone makes a reply to a topic in my forum I have a session variable setup to direct them back to the topic after it's been submitted. I do this by using: if (isset($_GET['topic_id'])) { $_SESSION['topic_id'] = $_GET['topic_id']; } The problem I have is when I want to create a new topic rather than post a reply. The topic_id has not been created yet so therefore I can't set a session to it. I'd like to have the user taken to their topic after it's been created. Any ideas on how to accomplish this? Thanks! Quote Link to comment Share on other sites More sharing options...
wsantos Posted December 8, 2007 Share Posted December 8, 2007 Try... if (isset($_GET['topic_id'])) { $_SESSION['topic_id'] = $_GET['topic_id']; } else { if(isset($_GET['topic_name'])) { $query="select topic_id from topics where topic_name = $_GET['topic_name']"; // etc } } Quote Link to comment Share on other sites More sharing options...
L Posted December 9, 2007 Share Posted December 9, 2007 How does setting a session bring you back to a topic when you post in it? ??? Quote Link to comment Share on other sites More sharing options...
L Posted December 9, 2007 Share Posted December 9, 2007 Anyone? I need a better way than having them wait for the page to refresh Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 9, 2007 Share Posted December 9, 2007 somehow youll have to create a variabel that stores boolean: reply or new post. once youve validated that its a new post ( no set Topic_ID) - then you add code at the top of the page to where its all sent. that page will submit the post - and retrive the ID back out again. I have to do it for my create user script. eg: NEW POST ==> SUBMIT POST TO DATABASE ==> retreive the ID again ==> WRITE TO SESSION VARIABLE Instead of using a timestamp to get that POST, why dont you use that first 10 characters of the message, because theyll still be stored in $_POST variables on that script? eg $Message $_POST['MESSAGE']; ### WRITE THIS TO DATABASE $SQL = SELECT * FROM POSTS WHERE MESSAGE == ".$Message"; ### RUN ANOTHER QUERY...... and youll have your message data again with the database auto increment values etc. Hope this helps Quote Link to comment Share on other sites More sharing options...
L Posted December 9, 2007 Share Posted December 9, 2007 I still don't see how making it a session takes you back to your post...like I have a refresh tag to go back to the thread... Quote Link to comment Share on other sites More sharing options...
L Posted December 9, 2007 Share Posted December 9, 2007 Anyone?... ??? Quote Link to comment Share on other sites More sharing options...
fert Posted December 9, 2007 Share Posted December 9, 2007 http://www.phpfreaks.com/quickcode/Redirect/532.php Quote Link to comment Share on other sites More sharing options...
Yesideez Posted December 9, 2007 Share Posted December 9, 2007 As long as nothing has been sent to the browser yet you can use the header() function, something like this: 1. User makes a new topic/replies to a topic 2. Script adds the topic/reply 3. Use something like this to redirect... header("Location: readtopic.php?topic=".$topicID); exit; 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.