2013-03-27 200 views
-3

不斷收到以下代碼的$結尾錯誤。我通過使用鍵盤清除了一些錯誤,但現在我卡住了。我知道這與冒號和分號有關,但我似乎不知道問題出在哪裏。 HELP

<?php 

$dbName=""; 
$dbUsername=""; 
$dbPassword=""; 

$fromPC=$_POST['fromPC']; 
$toPC=$_POST['toPC']; 


// 

function getDistance($lat1, $long1, $lat2, $long2, $unit) 
{ 

    if($unit=="miles"){ 
     $earth = 3960; //miles 
    }else{ 
    $earth = 6371; //kilometres 
    } 

    //From co-ordinates 
    $lat1 = deg2rad($lat1); 
    $long1= deg2rad($long1); 

    //To co-ordinates 
    $lat2 = deg2rad($lat2); 
    $long2= deg2rad($long2); 

    // The Haversine Formula 
    $dlong=$long2-$long1; 
    $dlat=$lat2-$lat1; 

    $sinlat=sin($dlat/2); 
    $sinlong=sin($dlong/2); 

    $a=($sinlat*$sinlat)+cos($lat1)*cos($lat2)*($sinlong*$sinlong); 

    $c=2*asin(min(1,sqrt($a))); 



$d=round($earth*$c); 

    return $d; 
} 




if((!empty($fromPC)) && (!empty($toPC))) 
{ 
    mysql_connect("********",$dbUsername,$dbPassword); 
    @mysql_select_db($dbName) or die("Unable to select database"); 

    // basic cleaning of input 
    $firstPC = strtoupper(preg_replace("/[^a-zA-Z0-9]/","",)); 
    $secondPC = strtoupper(preg_replace("/[^a-zA-Z0-9]/","",)); 

    // get first details 
    $query = 'SELECT `latitude`, `longitude` FROM `uk_postcodes` WHERE `postcode`="'.$firstPC.'";'; 
    $result = mysql_query($query); 
    $first = mysql_fetch_row($result); 
    $checkFirst=mysql_num_rows($result); 

    // get second details 
    $query = 'SELECT `latitude`, `longitude` FROM `uk_postcodes` WHERE 

`postcode`="'.$secondPC.'";'; 
    $result = mysql_query($query); 
    $second = mysql_fetch_row($result); 
    $checkSecond=mysql_num_rows($result); 

    // ensure there were results to calculate with 
    if(($checkFirst<1) || ($checkSecond<1)){ 
     $outputResults="Unrecognised postcode entered."; 
    }else{ 
     $distance = getDistance($first[0], $first[1], $second[0], $second[1], "miles"); 
     $outputResults = "The distance between postcode: $firstPC and postcode: $secondPC is ".$distance." miles."; 
    } 

    // always close your connections !! 
    mysql_close(); 
} 

?> 


<?=$outputResults?> 
+1

檢查:http://cs.wellesley.edu/~cs111/review_materials/conditionals.html – hek2mgl 2013-03-27 16:19:07

+1

無知道你的問題實際上是。這就是爲什麼你減少選票。嘗試改寫你的問題是什麼,並可能在問題中粘貼你的實際錯誤 – Brad 2013-03-27 16:19:23

+0

我馬上注意到的是:a)你已經包含了一個;在你的SQL查詢結束時,b)你使用的是舊的mysql驅動程序,而不是mysqli,你可以通過參數傳遞值,c)你已經在問題中包含了完整的訪問證書到你的數據庫中,d)這兩個選擇可以很容易地寫成一個。 – Patrick 2013-03-27 16:30:32

回答

0

解析錯誤,這

$firstPC = strtoupper(preg_replace("/[^a-zA-Z0-9]/","",)); 
    $secondPC = strtoupper(preg_replace("/[^a-zA-Z0-9]/","",)); 

應該

$firstPC = strtoupper(preg_replace("/[^a-zA-Z0-9]/","","Any String")); 
    $secondPC = strtoupper(preg_replace("/[^a-zA-Z0-9]/","","Any String"));