PHP - Go Back 2 Pages With Loaded Page Refreshed
when the user clicks the submit button from a html form, it needs to go back two pages with that loaded page refreshed. for the javascript i only have history.go(-2); with php, I have tried cookies and sessions which i discovered that neither will work because the loaded page is not refreshed. I could do a html body onload but that would break the w3c validator. what are my options?
Similar TutorialsHow can I detect if the page was refreshed? I thought the following worked, however, after much head scratching, discovered it does not work for a POST request using the Chrome browser. Thanks
<?php $refresh=isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0'; echo(($refresh?'refresh':'not refresh').'<br>'); echo('$_GET<pre>'.print_r($_GET,1).'</pre>'); echo('$_POST<pre>'.print_r($_POST,1).'</pre>'); ?> <ul> <li><a href="refresh.php?id=1">one</a></li> <li><a href="refresh.php?id=2">two</a></li> <li><a href="refresh.php?id=3">three</a></li> </ul> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="text" value="hello"> <input type="submit" name="submit" value="submit"> </form> Hello all, As the title says: For sake of example, let's say I have a form with a couple text boxes and a submit button. When you hit submit, the data from the text boxes is translated into a database record. Howver, refershing the page will this record again and again -- which I do not want. How can I prevent this? Keeping in mind the business logic of my applicatoin allows the same record to be entered twice -- however, it should only happen if the user intentionally visits the form agian, and enters the same data. It should not happen on a page refresh. I assume this is a common problem...? Any thoughts? Thanks! Hi guys, On my website i have a message inbox, and the code below is used to display and delete messages. When i tick the checkbox and click the delete button, the message gets deleted. The page appears to refresh after the submit button is clicked, however the message remains in the inbox, i have to refresh the page a second time for the message to disappear. Im trying to get it that when i press the submit button and the page reloads, the message disappears. Does anybody know of a technique that im not using or does anybody know if the code im using is wrong? <?php $messages_query = mysql_query("SELECT * FROM messages WHERE recipient='$username'"); if (mysql_num_rows($messages_query) > 0) { echo "<form method='POST' action='inbox.php'>"; while ($messages_row = mysql_fetch_array($messages_query)) { if ($messages_row['message_read'] == 0) { echo "<div style='background-color:#FFCCCC;'>"; } $message_id = $messages_row['id']; echo "<a href='message.php?id=$message_id'>"; echo "From: " . $messages_row['sender']; echo "Subject: " . $messages_row['subject'] . "<br />"; echo "</a>"; echo "<input type='checkbox' name='message[]' value='$message_id' />"; if ($messages_row['message_read'] == 0) { echo "</div>"; } } } else { echo "No messages"; } if ($submit) { foreach ($_POST['message'] as $msgID) { mysql_query("DELETE FROM messages WHERE id='$msgID'"); } } ?> <html> <input type="submit" name="submit" value="Delete" /> </form> </html> Many thanks Hi Guys, Im trying to create a registration form so users can sign up to my website, however i have noticed that when the page is refreshed the form automatically submits. Please could somebody help me stop this? Thanks <body> <form name="registration_form" method="post" onsubmit="return Validate();"> First Name: <input type="text" name="first_name"><br /> Last Name: <input type="text" name="last_name"><br /> Email: <input type="text" name="email"><br /> Confirm Email: <input type="text" name="confirm_email"><br /> Username: <input type="text" name="username"><br /> Password: <input type="password" name="password"><br /> Confirm Password: <input type="password" name="confirm_password"><br /> <input type="submit" value="Register"> </form> <?php $connect=mysql_connect("localhost","leemp5_admin","p7031521"); mysql_select_db("leemp5_database",$connect) or die (mysql_errno().":<b> ".mysql_error()."</b>"); $insert_query = 'insert into users (username,first_name,last_name,email,password) values ( "' . $_POST['username'] . '", "' . $_POST['first_name'] . '", "' . $_POST['last_name'] . '", "' . $_POST['email'] . '", "' . $_POST['password'] . '" )'; mysql_query($insert_query); ?> </body> i have a problem i just noticed....i've built a shopping cart that totals quantities of items and shipping etc then a submit button to a payment page... but if a user refreshes the same page after first coming to the cart page it messes up all the totals and data..... i know this has to be a common problem with webpages... does anyone have any advice on combating this issue? any advice is much appreciated..thanks! Please, take a look to the following code.After clicking Next it goes to overview.php.Why when I click back on my browser to return to this page again, it is not returning back? When I click back I receive "Confirm Form Resubmission" message. After refreshing page it loads page. I guess problem is in "session_start();" part. Something to do with cookies. Please, help me it is very urgent for me. <?php session_start(); echo "<html> <head> <title>Hello World</title> <meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'/> </head>"; require_once ('functions.inc'); if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'index.php'"; echo "</script>"; exit; }else{ session_register("userid", "userpassword"); $username = auth_user($_POST['userid'], $_POST['userpassword']); if(!$username) { $PHP_SELF = $_SERVER['PHP_SELF']; session_unregister("userid"); session_unregister("userpassword"); echo "Authentication failed " . "Please, write correct username or password. " . "try again "; echo "<A HREF=\"index.php\">Login</A><BR>"; exit; } } function auth_user($userid, $userpassword){ global $default_dbname, $user_tablename; $user_tablename = 'user'; $link_id = db_connect($default_dbname); mysql_select_db("d12826", $link_id); $query = "SELECT username FROM $user_tablename WHERE username = '$userid' AND password = '$userpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)){ return 0; }else{ $query_data = mysql_fetch_row($result); return $query_data[0]; } } echo "hello"; echo "<form method='POST' name='myform' action='overview.php'>"; echo "<input type='submit' value='Next'>"; echo "</form>"; ?> When I use the following code, it doesn't print out "test" until after I refresh the page. unset($_SESSION["product"]);
if ( !empty($_SESSION["product"]) && ($_SESSION["product"] != NULL)) { When I use: var_dump($_SESSION["product"]); It shows: array(0) { } I'm wondering it that's the problem. That it's array(0) when it should be array(). Hello i am trying to make the admin login in a webpage and after I completed the page i uploaded it and now the page is not loading
Here is the script
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); exit(); ?> <?php session_start(); if (!isset($_SESSION["manager"])){ header("location:admin_login.php"); exit(); } exit(); ?> <?php if(isset($_POST["username"])&&isset($_POST["password"])){ $manager=preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]); $password=preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]); include"../storescripts/connect_to_mysql.php"; $sql=mysql_querey("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); if($existCount == 1){ while($row = mysql_fetch_array($sql)){ $id = $rpw["id"]; } $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); } else { echo 'That Information is incorrect, try again <a href="index.php">Click Here</a>'; exit(); } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin Login</title> <link rel="stylesheet" href="k../style/style.css" type="text/css" media=="screen" /> <script type="text/javascript" src="//use.typekit.net/jxp6vds.js"></script> <script type="text/javascript">try{Typekit.load();}catch(e){}</script> </head> <body> <div align="centre" id="mainWrapper"> <?php include_once("../template_header.php") ?> <div id="pageConntent"> <h2>Please Log In To Manage The store</h2> <form id="form1" name="form1" meathod="post" action="admin_login.php"> Username:<br/> <input name="username" type="text" id="username" size="40"/> <br/><br/> Password<br/> <input name="password" type="password" id="password" size="40"/> <br/> <br/> <br/> <input type="submit" name="button" id="button" value="Log In" /> </form> </div> <?php include_once("../footer.php"); ?> </div> </body> </html>Thank you in advance Ok, just another noob problem here while working with PHP + MySQL: I have a php page containing a form which I use to pull the data from mysql database. When the user chooses a value/values from the dropdown lists and clicks submit, the page reloads and displaying the quarry results according to user's selection. When user first loads the php page with form, it shows no data unless he clicks submit. Question: How to show a default quarry value on first page load before user even get to use the form? In other words, I want the user to see the default quarry data pulled from DB on page load before he uses the form to refine the results... I am not sure if its possible, but truly hope so I would appreciate any advice or pointer in the right direction. Please let me know if you need the exact code I am using for my form page. Good evening, I am currently doing a web application which requires pulling out of data from the database. I am still a novice in the programming industry, and is still seeking help from my colleagues and of course forum sites like phpdn. I have an existing code which my friend provided me. I have already done some modifications with the code. I have a problem though with the code, it executes database query upon loading of the page. I do understand how the code works, however, I am not able to modify the code to disallow the execution of query upon loading of page. Here is the code: <?PHP include("dbconnection.php"); $query = "SELECT * FROM records"; if(isset($_POST["btnSearch"])) { $query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' " ; } $result = mysql_query($query, $connection) or die(mysql_error()); ?> I do know that this php code, the way it is written, is supposed to do that - to select data from my database (This code was provided by a friend). But my requirement for the project is actually to give it a search engine and display the information based from the search query. I have a search engine already together with the code, and it works pretty well. What I must do is to disallow the pulling of data from the first load, but just pull data if the search engine is used. Here's the whole code: <link href="add_client.css" rel="stylesheet" type="text/css"> <?PHP include("dbconnection.php"); $query = "SELECT * FROM records"; if(isset($_POST["btnSearch"])) { $query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' " ; } $result = mysql_query($query, $connection) or die(mysql_error()); ?> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="760" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="199" align="center" valign="top"><a href="login.html"><img src="asia.gif" alt="" width="152" height="58" border="0" /></a> <script type="text/javascript" src="menu.js"></script></td> <td width="176" align="right" valign="bottom"><a href="main.php"><img src="Home.jpg" width="104" height="20" border="0"/></a></td> <td width="130" align="right" valign="bottom"><img src="View.jpg" width="104" height="20" border="0"/></td> <td width="146" align="right" valign="bottom"><a href="add_client.php"><img src="Add.jpg" width="104" height="20" border="0"/></a></td> <td width="109" align="right" valign="bottom"> </td> </tr> </table></td> </tr> <tr> <td><table width="760" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="200" height="3" bgcolor="#1B1C78"><img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"><img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> </tr> </table></td> </tr> <tr> <td height="553" align="center" valign="top" bgcolor="#F3FAFE"><br /> <form name="form" action="view_client.php" method="post"> <table width="351" border="0"> <tr> <td width="137" align="left" valign="middle">SEARCH RECORD:</td> <td width="144" align="center" valign="middle"><input type="text" name="search" /></td> <td width="56" align="left" valign="middle"><input type="submit" name="btnSearch" value="Search" /></td> </tr> </table> <br /> <table width="680" border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="100" align="center" bgcolor="#E0E8F3">Territory</th> <th width="110" align="center" bgcolor="#E0E8F3">Employer</th> <th width="110" align="center" bgcolor="#E0E8F3">Job Title</th> <th width="50" align="center" bgcolor="#E0E8F3">Title</th> <th width="110" align="center" bgcolor="#E0E8F3">First Name</th> <th width="110" align="center" bgcolor="#E0E8F3">Last Name</th> <th width="70" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $job_title = trim(mysql_result($result, $i, "job_title")); $title = trim(mysql_result($result, $i, "title")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$job_title."</td>"; echo "<td>".$title."</td>"; echo "<td>".$first_name."</td>"; echo "<td>".$last_name."</td>"; echo "<td><a href='admin_edit.php?id=".$id."'>edit</a> | <a href='admin_delete.php?id=".$id."'>del</a> </td>"; echo "</tr>"; } } ?> </table> <br /> </form> <p> </p></td> </tr> <tr> <td height="38"><table width="760" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white><img src="images/topspacerblue.gif" alt="" width="1" height="3" /> <a href="disclaimer.html"><font color="#FFFFFF">Legal Disclaimer</font></a> </td> <td width="560" align="center" bgcolor="#0076CC" class=white><img src="images/topspacerlblue.gif" alt="" width="1" height="3" /> Copyright © 2006 - 2010 Limited. All rights reserved. </td> </tr> </table></td> </tr> </table> Immediate response is well appreciated. Thank you very much! I'm restarting this under a new subject b/c I learned some things after I initially posted and the subject heading is no longer accurate. What would cause this behavior - when I populate session vars from a MYSQL query, they stick, if I populate them from an MSSQL query, they drop. It doesn't matter if I get to the next page using a header redirect or a form submit. I have two session vars I'm loading from a MYSQL query and they remain, the two loaded from MSSQL disappear. I have confirmed that all four session vars are loading ok initially and I can echo them out to the page, but when the application moves to next page via redirect or form submit, the two vars loaded from MSSQL are empty. Any ideas? I have the following code. Before back button was working. Now don't understand what happend but when I click Back button I receive "Webpage has expired" window in my browser. What may be the reason? Code: [Select] <html> <head> <title>Økern Frukt og Grønt</title> <link href="calendar/calendar.css" rel="stylesheet" type="text/css" /> <script language="javascript" src="calendar/calendar.js"></script> <style type="text/css"> textarea { resize: none; } </style> <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/> </head> <?php if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'login.html'"; echo "</script>"; exit; } require_once ('functions.inc'); require_once('calendar/classes/tc_calendar.php'); global $default_dbname; $link_id = db_connect($default_dbname); mysql_select_db("okern", $link_id); $letters1 = array ("A1", "B1", "C", "D","E", "F", "G", "H","I", "J", "K", "L", "M", "N", "O", "P","Q", "R", "S", "T","U", "V", "W", "X", "Y", "Z", "&#198", "&#216", "&#197"); $letters = array_merge(range("A", "Z"), array("&#38;#198", "&#38;#216", "&#38;#197")); echo "<table border='0' align='center'> <tr> <td colspan=3><b><center>Du har valgt f&#248lgende produkter</center></b></td> </tr> <tr> <th align=left>Produkt</th> <th align=left>Antall</th> <th align=left>Enhet</th> </tr>"; echo "<form method='POST' action='order.php'>"; $userid = $_POST['userid']; echo "<INPUT TYPE='hidden' NAME='userid' VALUE='$userid'>"; foreach($letters as $letter) { if(isset($_POST[$letter])) { $selected = $letter . '1'; $antall = $letter . '2'; $enhet = $letter . '3'; echo "<tr>"; echo "<td>" . "<INPUT TYPE='hidden' NAME='$selected' VALUE='$_POST[$selected]'>" . "$_POST[$selected]" . "</td>"; echo "<td>" . "<INPUT TYPE='hidden' NAME='$antall' VALUE='$_POST[$antall]'>" . "$_POST[$antall]" . "</td>"; echo "<td>" . "<INPUT TYPE='hidden' NAME='$enhet' VALUE='$_POST[$enhet]'>" . "$_POST[$enhet]" . "</td>"; echo "</tr>"; } } for ($i = 1; $i < 400; $i++) { if (isset($_POST[$i])){ $selected = 'a' . $i; $antall = 'antall' . strval($i); $enhet = 'enhet' . strval($i); echo "<tr>"; echo "<td>" . "$_POST[$selected]" . "</td>"; echo "<td>" . "$_POST[$antall]" . "</td>"; echo "<td>" . "$_POST[$enhet]" . "</td>"; echo "</tr>"; } } echo "<tr height=10></tr> <tr><td colspan=2>Velg dato for bestillingen:</td> <td colspan=1>"; $myCalendar = new tc_calendar("date5", true, false); $myCalendar->setIcon("calendar/images/iconCalendar.gif"); $myCalendar->setDate(date('d'), date('m'), date('Y')); $myCalendar->setPath("calendar/"); $myCalendar->setYearInterval(2000, 2015); $myCalendar->dateAllow('2008-05-13', '2015-03-01'); $myCalendar->setDateFormat('j F Y'); $myCalendar->setAlignment('left', 'bottom'); $myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year'); $myCalendar->writeScript(); echo "<INPUT TYPE='hidden' NAME='date' VALUE='this.form.date5.value'>"; echo "</td></tr>"; echo "<tr height=10></tr><tr> <td colspan=3>Skrive din melding nedenfor:</td> </tr>"; echo "<tr> <td colspan=3><textarea name='melding' cols='50' rows='5' resize=none></textarea></td> </tr>"; echo "<tr> [b]<td><center><input type='button' value='Tilbake' onClick='history.go(-1)'></center></td>[/b] <td colspan=2><center><input type='submit' value='Bestil'></center></td> </tr>"; echo "</form>"; echo "</table>"; ?> </html> I need some help with a form being successfully submitted redirecting to a secure page. I already have the form code working and just need the part to redirect within an else statement. Also need to redirect a user back to the form page if they try and visit the secure page without being a member. thanks in advance. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321154.0 Hello everyone. I am writing this order/feedback form using a php script.
Every time i hit submit, the html page (that has the form inside) just reloads and does not perform the script
could anyone give me some pointers in my code the form/php?
I have made sure they are linked verbatim
I am a nube so please forgive my inexperience
Here is the form in the html , down below it is the corresponding php code for the form
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330185.0 Ok i have a question about a dynamic website.. What i have is a site that takes content from the MySQL database and load it into the index.php file. And i know how to change the content of the page when i move around in the navigation, e.g when i click on the "HOME" tab, the content for the home page is shown and when i click on "ABOUT", the information about my site is shown and so on.. Now for my question! I want the content too move everyday automaticly. For example, today i type in some content in the MySQL database that i want to be shown on my website for today. But tomorrow i want the content to have been moved to page 2, and the next day page 3 and so on.. So that everyday i can type in new content, and all the old pages get pushed back one page if that makes sense? Sorry but I have no actuall code for this cause i don't know how to start, but i guess you could use dates and "if else" statements to determine when the pages should be moved and not. Example code would be greatly appriciated! And when i say moved between pages, i mean like this: Today: www.mywebsite.com/index.php?pageid=1 - example 2 www.mywebsite.com/index.php?pageid=2 - example 1 www.mywebsite.com/index.php?pageid=3 - empty Tomorrow: www.mywebsite.com/index.php?pageid=1 - example 3 www.mywebsite.com/index.php?pageid=2 - example 2 www.mywebsite.com/index.php?pageid=3 - example 1 Folks, I am trying to grab the value selected in a Dropdown, with $_GET['q']. Then i am echoing the grabbed value. Funny thing is, when i select value from HTML dropdown (onchange="location=this.value"), and when a new value is selcted, it appaears in url like this: Quote http://www.abc.com/?search=selected-value.html But when i try to grab and echo the value of 'q' it gets passed only when i refresh the page and not when i change my selecting in dropdown. Am not sure whats happening, can someone help me on this? Cheers NT this is my code which is using to check login from database calledchklogin.php Code: [Select] <?php session_start(); include('connect.php'); $tbl_name="members"; mysql_select_db($Db, $link); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $mypassword = md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE uname='$myusername' and upass='$mypassword'"; $result=mysql_query($sql,$link); $row=mysql_fetch_array($result); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("username"); //Create the session session_register("myusername"); session_register("mypassword"); $_SESSION['uname'] = "$myusername"; $_SESSION['utype'] = $row['utype']; header("location:loginsuccess.php"); } else { //include ('index.php'); echo ("<script type='text/javascript'> window.alert('Wrong username or password!')</script>"); exit(); } ?> & this code is from another file called loginsuccess.php Code: [Select] <? session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); exit(); } require_once("login-index.php"); ?> so when everything is right in chklogin.php then it open loginsuccess.php after that when all is true then it open login-index.php after that this page open it show double page one is index.php where the login form & another is this login-index.php at one time Hello, I'm new here and need some help. I'm a beginner with PHP Here's what I have.... The index page looks like this: <? include("header.php"); ?> <? include("sidebar.php"); ?> <? include("main.php"); ?> <? include("footer.php"); ?> On all of the pages for the site, the only thing that will change will be: <? include("main.php"); ?> When viewing the home page, the title in the browser shows: Home Page (which is what I want). However, when clicking on links in the nav bar, I want the title to reflect those page names. For example, the code above displays the home page, but then if you click on (for example) "Bio's" in the navigation bar, it will take you to the Bio's page, obviously. the link for that menu item is: bio.php. The bio.php page looks like this: <? include("header.php"); ?> <? include("sidebar.php"); ?> <div> All the data and formatting for this page </div> <? include("footer.php"); ?> ............. I would like to put some php code in the header that will automatically detect the title of each page, how can I do this? Should I put <? title=Bio's Page ?> (or whatever page) at the top of each page, then call to it somehow from the header? Any help would be appreciated. |