1 - User enters an information in a text field (form) in page1.php and clicks on submit button;
<Form name="search_form" method="POST" action="page2.php">
<input type="text" name="search_box" class="btn btn-default" value="" />
<input type="submit" name="search" class="btn btn-default" value="Search location">
</form>
<br>
2 - This information entered by the user in page1.php is sent to page2.php where I use it to do a query in my database and save it in a xml file.
<?php
require("phpsqlajax_dbinfo.php");
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
if (isset($_POST['search'])){
$search_term = mysql_real_escape_string($_POST['search_box']);
$query = "SELECT * FROM markers WHERE area= '{$search_term}' OR county = '{$search_term}' OR name = '{$search_term}' OR road = '{$search_term}' ORDER BY petrol ASC";
}
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("id",$row['id']);
$newnode->setAttribute("name",$row['name']);
$newnode->setAttribute("address",$row['address']);
$newnode->setAttribute("lat",$row['lat']);
$newnode->setAttribute("lng",$row['lng']);
}
echo $dom->saveXML();
?>
Everything great so far!
Now I need redirect the user to page3.php where the information entered by the user in page1.php, filtered and saved on page2.php is going to be load over a map on page3.php.
Issue: If I use header("Location: page3.php") in page2.php, the user is redirected to page3.php but the information from my query from page2.php seems not be executed/saved and don´t load on page3.php.
If I use another xml file in the code from page3.php it works.So, I conclude that my issue is in page2.php.
Page3.php
<script type="text/javascript">
var customIcons = {
gas_station: {
icon: '/icon.png'
},
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(53.349535, -6.262184),
zoom: 10,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("page2.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var convenience = markers[i].getAttribute("convenience");
var atm = markers[i].getAttribute("atm");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>Station: </b>" + name + "<br/><b>Address: </b>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
Is there anyway that when the user clicks on submit in page1.php the information be sent to page2.php and also the user be automatically redirected to page3.php.
Thank you in advance!
Following is a very basic implementation of using localStorage:
Note: Stackoverflow does not allow access to localStorage, so kindly test on JSFiddle.
function saveToLocalStorage() {
var value = document.getElementById("txt").value;
console.log(value);
localStorage.setItem("myValue", value);
}
function getFromLocalStorage(){
console.log(localStorage.getItem("myValue"));
}
<input type="text" id="txt">
<button onclick="saveToLocalStorage()">Save</button>
<button onclick="getFromLocalStorage()">Get</button>
</div>
Im assuming that you are sending non-sensitive information...you can always send information via GET method from page 2 to page 3 and recieve the information in page 3..