Forum Moderators: coopster

Message Too Old, No Replies

Any way to keep form "POST" data in memory?

         

aerotwelve

12:22 am on Jul 8, 2007 (gmt 0)

10+ Year Member



Hello,

I'm working on a form of rating system for user generated stories, somewhat like Digg and Slashdot. The way users get to stories is by putting in the ID of the story in a box and the script pulls it up, and the post data is what the script uses to find the story. My problem is when one goes to rate a story, that post data is gone, and I can't think of a way to keep that in memory.

In case I didn't make that clear, here are the variables that are crucial.

$linkid = $_POST['linkid'];
$result = mysql_query("SELECT * FROM links WHERE link_id = linkid");

Essentially, everything refers to itself through that post data. Is there any way to keep that in memory, so things can work? If I'm doing this completely wrong, I'm willing to rewrite it.

Habtom

4:48 am on Jul 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would say give the visitor a unique temporary id (session id), and save the persons activities to a database.

You can carry the values along with sessions too.

I want to hear if there are more ways of doing it.

cameraman

8:55 am on Jul 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the page that displays the story has the rating form on it, you can carry it straight in:
$result = mysql_query("SELECT * FROM links WHERE link_id = $linkid");
.
.
.
<div><?php echo $story;?></div>
<form>
Your rating <input...>
<input type="hidden" name="linkid" value="<?php echo $linkid;?>">
</form>

You can also move it into the url and subsequently retrieve it with GET
<div>story</div>
<div>Click <a href="ratestory.php?id=<?php echo $linkid;?>">here</a> to rate the story</div>

If that's all you have to save, you don't really need to put it into a database, just use sessions:
$_SESSION['id'] = $linkid;

Then on the page that needs it:
$linkid = $_SESSION['id'];

You may need to use session_start() [us.php.net] if session.auto_start isn't set in your php configuration.