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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/ 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-409683 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410068 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410510 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410530 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410538 Share on other sites More sharing options...
L Posted December 9, 2007 Share Posted December 9, 2007 Anyone?... ??? Quote Link to comment https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410556 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410566 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 https://forums.phpfreaks.com/topic/80771-returning-to-user-to-their-topic-after-creating-it/#findComment-410571 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.