Nexy Posted July 7, 2008 Share Posted July 7, 2008 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! Link to comment https://forums.phpfreaks.com/topic/113497-solved-save-variable-after-changing-pages/ Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 Sessions work if you do them correctly. Do you have session_start() on every page that requires sessions? Link to comment https://forums.phpfreaks.com/topic/113497-solved-save-variable-after-changing-pages/#findComment-583175 Share on other sites More sharing options...
Nexy Posted July 7, 2008 Author Share Posted July 7, 2008 Yes, I do. But it didn't work the way I did it. I replaced $pm_set = "1"; with $_SESSION['pm_set'] = "1"; and the other with "2". And it didn't display anything under the echo. Link to comment https://forums.phpfreaks.com/topic/113497-solved-save-variable-after-changing-pages/#findComment-583176 Share on other sites More sharing options...
Nexy Posted July 7, 2008 Author Share Posted July 7, 2008 Nvm, I figured it out. Link to comment https://forums.phpfreaks.com/topic/113497-solved-save-variable-after-changing-pages/#findComment-583183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.