我已经为此困扰了将近一天,我无法弄清楚这里有什么问题。我需要$_POST['brand']
在这里的 SQL 语句,我得到一个空白。
// sql for getting nearby stores
$sql = "SELECT *, ( 3959 * ACOS( COS( RADIANS(".$_POST['lat'].") ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(".$_POST['lng'].") ) + SIN( RADIANS(".$_POST['lat'].") ) * SIN( RADIANS( latitude ) ) ) ) AS distance
FROM stores
WHERE brand='".$_POST['brand']."'
HAVING distance <= ".$_POST['distance']."
ORDER BY distance";
这是 PHP 文件中的表单。
<form method="post" action="./index.php" id="store_locator">
<fieldset>
<legend>Store Locator</legend>
<div class="input">
<label>Address/Postcode: <span class="required">*</span></label>
<input type="text" class="texta" name="address" id="address" value="<?php if(isset($_POST['address'])){ echo $_POST['address'];} ?>" />
<span>e.g: "Sydney", "Magill Road"</span>
</div>
<div class="input">
<label>Brand: <span class="required">*</span></label>
<select name="brand" id="brand">
<option selected="selected" value="bmw">BMW</option>
<option value="fiat">Fiat</option>
<option value="ford">Ford</option>
</select>
<label>Distance: <span class="required">*</span></label>
<select name="distance" id="distance">
<?php
// populate selected option
$selected = 1;
if(isset($_POST['distance'])) {
$selected = $_POST['distance'];
}
?>
<?php foreach($distances as $k=>$v): ?>
<option value="<?php echo $k; ?>" <?php if($selected == $k){ echo 'selected="selected"';} ?>><?php echo $v; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="input buttons">
<button type="submit" name="find" id="find">Find</button>
</div>
</br>
<input type="button" value="Reset Map" onclick="reset2();" />
</fieldset>
</form>
我在这里想念什么?奇怪$_POST['distance']
的是获得价值。请帮忙。如果我回显brand =''
在 SQL 语句中看到的 SQL。
这是正在执行的 SQL 代码:
SELECT *, ( 3959 * ACOS( COS( RADIANS(-31.9530044) ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(115.85746930000005) ) + SIN( RADIANS(-31.9530044) ) * SIN( RADIANS( latitude ) ) ) ) AS distance FROM stores WHERE brand='' HAVING distance <= 30 ORDER BY distance
$_POST 的内容
array(5) {
["ajax"]=> string(1) "1"
["action"]=> string(17) "get_nearby_stores"
["distance"]=> string(1) "5"
["lat"]=> string(11) "-31.9530044"
["lng"]=> string(18) "115.85746930000005"
}