Jump to content

Returning to user to their topic after creating it


Eiolon

Recommended Posts

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!

Link to comment
Share on other sites

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
  }
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

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.