MySQL Forums
Forum List  »  PHP

Passing variable from form to php for SQL select
Posted by: Jim DiGiovanni
Date: February 14, 2016 03:00PM

I have an HTML file that passes the variable 'radius' to my php file :

<body style="margin:0px; padding:0px;" onload="load()">
<div>
<input type="text" id="addressInput" size="10"/>
<select id="radiusSelect">
<option value="1" selected>1mi</option>
<option value="5" selected>1mi</option>
<option value="10">10mi</option>
<option value="25">25mi</option>
<option value="100">100mi</option>
</select>
<input type="button" class="search-locations" value="Search">
</div>
<div><select id="locationSelect" style="width:100%;visibility:hidden"></select></div>
<div id="map" style="width: 100%; height: 80%"></div>
</body>

The php file phpsqlsearch_genxml gets the variable, performs a select statement and later in the code generates an XML file for Google map display.


$connection = mysql_connect ("$dbserver", "$dbuser", "$dbpass");
mysql_select_db("$dbname") or die(mysql_error());

// Search the rows in the markers table
$query = sprintf("SELECT job, contractor, status, util1, util2, inspector, address, city, lname, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM inspections WHERE status='O' HAVING distance< '%s' ORDER BY distance LIMIT 0 , 200",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);

if (!$result) {
die("Invalid query: " . mysql_error());
}

It currently works fine. I want to add the ability for the user to select the AGE of the inspection as well as the radius.

I have a field in inspections table called 'statusdt'.

I want to add the criteria :
(Todays's Date - statusdt as age) in the Select statement and then at the end of the statement it says 'WHERE status='O' AND age< NEWVARIABLE PASSED FROM HTML

The HAVING clause makes it tricky for me.

I am a new programmer. I am using this code I found in a google article and bastardized it to my own needs and it works but I want to add the functionality of filtering out old records.

I appreciate any help offered.
Thanks

Options: ReplyQuote


Subject
Written By
Posted
Passing variable from form to php for SQL select
February 14, 2016 03:00PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.