Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retain the value of a variable after sucessive submission of form
    primarykey
    data
    text
    <p>I am developing a Contextual Search Engine in php. For that when an user types a query, I need her latlong and time. I am developing the search box in php. To get latlong I am using HTML 5 geolocation api. I have written following two files by taking idea from posts in stackoverflow. </p> <p>order.php</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function getLocation(){ var x = document.getElementById("demo"); if (navigator.geolocation){ navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML="Geolocation is not supported by this browser."; } } function showPosition(position){ var latitude=document.getElementById("latitude"), longitude=document.getElementById("longitude"); latitude.value = position.coords.latitude; longitude.value = position.coords.longitude; } &lt;/script&gt; &lt;/head&gt; &lt;body onload="getLocation()"&gt; &lt;p id="demo"&gt;&lt;/p&gt; &lt;form id="searchbox" action="process.php" method="get"&gt; &lt;input name="q" type="text" placeholder="Type here"&gt; &lt;input name="latitude" id="latitude" type="hidden"&gt; &lt;input name="longitude" id="longitude" type="hidden"&gt; &lt;input id="submit" type="submit" value="Search"&gt; &lt;/form&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>Another file is process.php</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form id="searchbox" action="process.php" method="post"&gt; &lt;input name="q" type="text" placeholder="Type here"&gt; &lt;input name="latitude" id="latitude" type="hidden" value="&lt;?php $latitude=$_POST['latitude']; echo $latitude; ?&gt;"&gt; &lt;input name="longitude" id="longitude" type="hidden" value="&lt;?php $longitude=$_POST['longitude'];echo $longitude; ?&gt;"&gt; &lt;input id="submit" type="submit" value="Search"&gt; &lt;/form&gt; &lt;?php $quantity=$_POST['quantity']; $date = date('Y-m-d H:i:s'); $arr=explode(" ",$date); $latitude=$_GET['latitude']; $longitude=$_GET['longitude']; echo "Latitude=". $latitude."Longitude=". $longitude." Time=".$arr[1]."&lt;br&gt;"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The problem is that whenever I am submitting the form again from process.php the latitude and longitude values are getting reset. So how do I retain the value of them that I have got after landing on process.php so that they do not get reset even if I submit the form from process.php multiple times. </p> <p>In this context I have seen other similar questions asked here and applied their solutions but none of them seems to be working. So please help. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload