Jump to content

[SOLVED] Save variable after changing pages?


Nexy

Recommended Posts

Why Hello There! :) Just wondering how I would save a variable even after you change pages.

 

I have this:

 

<?php

if($_POST['pmsend'] && $_GET['do'] == "mod")
{
$sql = "SELECT username FROM users WHERE username = '$pmuser'";
$res = mysql_query($sql) OR die(mysql_error());

if(!empty($pmuser) && !empty($subject) && !empty($message) && mysql_num_rows($res) == 1)
{
	$pm_set = "1";

	if($_SESSION['user'])
	{
		mysql_query("INSERT INTO pm_inbox(user, sender, subject, date, message, status) 
				VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')");
		mysql_query("INSERT INTO pm_draft(user, sender, subject, date, message, status) 
				VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')");
	}
	else if($_COOKIE['user'])
	{
		mysql_query("INSERT INTO pm_inbox(user, sender, subject, date, message, status) 
				VALUES('$pmuser', '".$_COOKIE['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')");
		mysql_query("INSERT INTO pm_draft(user, sender, subject, date, message, status) 
				VALUES('$pmuser', '".$_COOKIE['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')");
	}
}
else if(empty($pmuser) || empty($subject) || empty($message) || mysql_num_rows($res) == 0) { $pm_set = "2"; }
}

if($pm_set == "1")
{
echo "<div class='create' style='width: 495px; padding: .2em; color: #00FF7F'>
	<img src='images/update.ico' alt='' /> Your Message to " . $_SESSION['suser'] . ' has been sent!
		</div>';
}
else if($pm_set == "2")
{
echo "<div class='create' style='width: 495px; padding: .2em; color: #CD5C5C'>
	<img src='images/remove.ico' alt='' /> Your message has encountered a problem!
		</div>";
}

?>

 

When you click submit on the form, it takes you to index.php?page=PM&pg=send&do=mod. After that it takes you back to index.php?page=PM&pg=send. But, once you change pages, I'm guessing the variable $pm_set doesn't have those values any more.

 

Since it doesn't have those variables, it doesn't echo the what is set under them. I tried using a session, but it still didn't display. My question is; is there any way I can save that variable's value once it changes pages and comes back and it shows the message? I did this, to stop the user from pressing refresh and inserting the same thing more than once.

 

I had <form action='index.php?page=PM&pg=send'>, but your still able to press refresh and insert multiple entries of the same thing. I can't use PHP_SELF because this is an included inside of index.php, so it would take me back to the main page. Any help would be appreciated.

 

Thank You! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.