Lamez Posted July 15, 2008 Share Posted July 15, 2008 Is there a way to refresh the page with php, and still keep the variables in tact? Link to comment https://forums.phpfreaks.com/topic/114879-solved-refresh-the-page/ Share on other sites More sharing options...
947740 Posted July 15, 2008 Share Posted July 15, 2008 Use sessions, and you will not have a problem. Metarefresh is the best way to refresh. Link to comment https://forums.phpfreaks.com/topic/114879-solved-refresh-the-page/#findComment-590746 Share on other sites More sharing options...
Lamez Posted July 15, 2008 Author Share Posted July 15, 2008 well I could use sessions, they are all on the same page. I thought there could be a better way to do this. <?php ob_start(); $path = "../../"; $title = "Ban Users"; $rank = "yes"; include ($path."main/include/cons/head.php"); if($session->logged_in){ if($session->isAdmin()){ $ban = mysql_query("SELECT `username` FROM `users` WHERE `ban` = '0' and `userlevel` = '1'"); $un = mysql_query("SELECT `username` FROM `users` WHERE `ban` = '1'"); if (isset($_POST['ban'])){ if (isset($_POST['user'])){ $user = $_POST['user']; mysql_query("UPDATE `users` SET `ban`='1' WHERE `username`='$user'")or die(mysql_error()); $message = $user." has been banned"; } } if (isset($_POST['un_ban'])){ if (isset($_POST['ban_user'])){ $banuser = $_POST['ban_user']; mysql_query("UPDATE `users` SET `ban`='0' WHERE `username`='$banuser'")or die(mysql_error()); $message = $banuser." has been unbanned"; } } ?> <p class="header">Ban Users</p> <p class="maintext"> <?php echo $message; ?> <br /> <form id="ban" name="ban" method="post" action=""> <table width="100%" border="0"> <tr> <td width="7%">Users List</td> <td width="13%"><label> <select name="user" id="user"> <?php while($row = mysql_fetch_array($ban)){ echo '<option value="'.$row['username'].'">'.$row['username'].'</option>'; } ?> </select> </label></td> <td width="80%"><label> <input type="submit" name="ban" id="ban" value="Ban User" /> </label></td> </tr> </table> </form> <br /> <form id="unban" name="unban" method="post" action=""> <table width="100%" border="0"> <tr> <td width="7%">Users List</td> <td width="13%"><label> <select name="ban_user" id="ban_user"> <?php while($row = mysql_fetch_array($un)){ echo '<option value="'.$row['username'].'">'.$row['username'].'</option>'; } ?> </select> </label></td> <td width="80%"><label> <input type="submit" name="un_ban" id="un_ban" value="unBan User" /> </label></td> </tr> </table> </form> </p> <?php }else{ header('Location: '.$path.'index.php'); } }else{ header('Location: '.$path.'index.php'); } include ($path."main/include/cons/foot.php"); ?> Link to comment https://forums.phpfreaks.com/topic/114879-solved-refresh-the-page/#findComment-590752 Share on other sites More sharing options...
947740 Posted July 15, 2008 Share Posted July 15, 2008 The variables will not have a value if you refresh the page, so I would just stick with that. Link to comment https://forums.phpfreaks.com/topic/114879-solved-refresh-the-page/#findComment-590753 Share on other sites More sharing options...
Lamez Posted July 15, 2008 Author Share Posted July 15, 2008 thanks for suggesting sessions variables, I got it to work just fine now. <?php ob_start(); $path = "../../"; $title = "Ban Users"; $rank = "yes"; include ($path."main/include/cons/head.php"); if($session->logged_in){ if($session->isAdmin()){ $ban = mysql_query("SELECT `username` FROM `users` WHERE `ban` = '0' and `userlevel` = '1'"); $un = mysql_query("SELECT `username` FROM `users` WHERE `ban` = '1'"); if (isset($_POST['ban'])){ if (isset($_POST['user'])){ $user = $_POST['user']; mysql_query("UPDATE `users` SET `ban`='1' WHERE `username`='$user'")or die(mysql_error()); $_SESSION['message'] = $user." has been banned"; header('Location: ban_us.php'); } } if (isset($_POST['un_ban'])){ if (isset($_POST['ban_user'])){ $banuser = $_POST['ban_user']; mysql_query("UPDATE `users` SET `ban`='0' WHERE `username`='$banuser'")or die(mysql_error()); $_SESSION['message'] = $banuser." has been unbanned"; header('Location: ban_us.php'); } } ?> <p class="header">Ban Users</p> <p class="maintext"> <?php echo $_SESSION['message']; ?> <br /> <form id="ban" name="ban" method="post" action=""> <table width="100%" border="0"> <tr> <td width="7%">UnBanned</td> <td width="13%"><label> <select name="user" id="user"> <?php while($row = mysql_fetch_array($ban)){ echo '<option value="'.$row['username'].'">'.$row['username'].'</option>'; } ?> </select> </label></td> <td width="80%"><label> <input type="submit" name="ban" id="ban" value="Ban User" /> </label></td> </tr> </table> </form> <br /> <form id="unban" name="unban" method="post" action=""> <table width="100%" border="0"> <tr> <td width="7%">Banned</td> <td width="13%"><label> <select name="ban_user" id="ban_user"> <?php while($row = mysql_fetch_array($un)){ echo '<option value="'.$row['username'].'">'.$row['username'].'</option>'; } ?> </select> </label></td> <td width="80%"><label> <input type="submit" name="un_ban" id="un_ban" value="unBan User" /> </label></td> </tr> </table> </form> </p> <?php }else{ header('Location: '.$path.'index.php'); } }else{ header('Location: '.$path.'index.php'); } include ($path."main/include/cons/foot.php"); ?> Link to comment https://forums.phpfreaks.com/topic/114879-solved-refresh-the-page/#findComment-590755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.