I have a storelocator for my client's website that uses a database to get all the information of the stores. This store locator works perfectly on my desktop and on my laptop local servers (localhost), but once I upload everything to my test site the store locator won't work. In a file called locate.php
I include a file/class called store.php
, when I go to the locate.php file on my localserver I only get notices which aren't a big deal.
When I go to my site, this error appears.
In the locate.php
I also include a file called defines.php
which has the information required to access the db (host, username, password, dbname). At first I thougt it could be a GoDaddy problem but I've used localhost and my website IP as the host, deleted and reuploaded the database and nothing seems to work.
Here are the files I've mentioned in this thread.
locate.php
include_once("./defines.php");
include_once("./class/store.php");
function vectorLength($x,$y){
return sqrt(($x*$x)+($y*$y));
}
$R=6378.1;
$count=0;
$total = $_GET['total'];
//$stores[$total];
//$distances[$total];
$lat=$_GET['lat'];
$lng=$_GET['lng'];
$maxdist=0;
$maxid=-1;
//first filter for 100km radius (0.9 degrees on equator = 100km)
$verified_stores = getStores("status=".VERIFIED." AND latitude > '".($lat-0.9)."' AND latitude < '".($lat+0.9)."' AND longitude > '".($lng-0.9)."' AND longitude < '".($lng+0.9)."'",NULL,0,0);
for($i=0;$i<count($verified_stores);$i++){
$clat = $verified_stores[$i]->latitude;
$clng = $verified_stores[$i]->longitude;
$dlat=$lat-$clat;
$dlng=$lng-$clng;
//second filter using haversine distance
$dLat=deg2rad($dlat);
$dLng=deg2rad($dlng);
//haversine calculations
$a = pow(sin($dLat/2),2)+cos(deg2rad($lat)) * cos(deg2rad($clat))*pow(sin($dLng/2),2);
$c = 2 * asin(sqrt($a));
$d = $R*$c;
if($d>$_GET['radius']) continue;
if($count<$total){
//keep track of farthest distance
if($maxdist<$d){
$maxdist=$d;
$maxid=$count;
}
//insert into list of not full
$stores[$count]=$verified_stores[$i]->storeID;
$distances[$count]=$d;
$count++;
}
else{
//scan distances
if($d<$maxdist){
//replace farthest store
$stores[$maxid]=$verified_stores[$i]->storeID;
$distances[$maxid]=$d;
$maxdist=0;
//find next maxid
for($j=0;$j<$total;$j++){
if($maxdist<$distances[$j]){
$maxdist=$distances[$j];
$maxid=$j;
}
}
}
}
}
//bubble sort stores
$total=$count;
for($i=0;$i<$total-1;$i++){
$swapped=false;
for($j=$i+1;$j<$total;$j++){
if($distances[$i]>$distances[$j]){
//swap $i and $j
$temp=$distances[$i];
$distances[$i]=$distances[$j];
$distances[$j]=$temp;
$temp=$stores[$i];
$stores[$i]=$stores[$j];
$stores[$j]=$temp;
$swapped=true;
}
}
}
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "
<LOCATIONS>
";
for($i=0;$i<$total;$i++){
$store = getStore($stores[$i]);
$clat=$store->latitude;
$clng=$store->longitude;
$dLat=deg2rad($lat-$clat);
$dLng=deg2rad($lng-$clng);
//haversine calculations
$a = pow(sin($dLat/2),2)+cos(deg2rad($lat)) * cos(deg2rad($clat))*pow(sin($dLng/2),2);
$c = 2 * asin(sqrt($a));
$d = $R*$c;
$webpage = $store->webpage;
if(strlen($webpage)==0) $webpage="<![CDATA[ ]]>";
echo "<STORE>
";
echo "<DIST>$d</DIST>
";
echo "<NAME><![CDATA[".htmlspecialchars($store->name)."]]></NAME>
";
echo "<ADDR>".htmlspecialchars($store->address)."</ADDR>
";
echo "<PHONE>".htmlspecialchars($store->phone)."</PHONE>
";
echo "<WEBPAGE>$webpage</WEBPAGE>
";
echo "<LAT>$clat</LAT>
";
echo "<LNG>$clng</LNG>
";
echo "</STORE>
";
}
echo "</LOCATIONS>
";
?>
store.php
<?php
class Store{
public $storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated;
public function __construct($storeID=NULL,$name=NULL,$contact=NULL,$address=NULL,$phone=NULL,$fax=NULL,$email=NULL,$webpage=NULL,$latitude=0,$longitude=0,$status=0,$created=NULL,$updated=NULL){
$this->storeID=$storeID;
$this->name=$name;
$this->contact=$contact;
$this->address=$address;
$this->phone=$phone;
$this->fax=$fax;
$this->email=$email;
$this->webpage=$webpage;
$this->latitude=$latitude;
$this->longitude=$longitude;
$this->status=$status;
//$this->enabled=$enabled;
$this->created=$created;
$this->updated=$updated;
}
public function toString(){
$s="StoreID: ".$this->storeID."<br/>";
$s.="Name: ".$this->name."<br/>";
$s.="Contact: ".$this->contact."<br/>";
$s.="Address: ".$this->address."<br/>";
$s.="Phone: ".$this->phone."<br/>";
$s.="Fax: ".$this->fax."<br/>";
$s.="E-mail: ".$this->email."<br/>";
$s.="Webpage: ".$this->webpage."<br/>";
$s.="Latitude: ".$this->latitude."<br/>";
$s.="Longitude: ".$this->longitude."<br/>";
$s.="Status: ".$this->status."<br/>";
$s.="Created: ".$this->created."<br/>";
$s.="Updated: ".$this->updated."<br/>";
return $s;
}
}
function restoreStore($id){updateStoreStatus($id,UNVERIFIED);}
function verifyStore($id){updateStoreStatus($id,VERIFIED);}
function unverifyStore($id){updateStoreStatus($id,UNVERIFIED);}
function trashStore($id){updateStoreStatus($id,RECYCLING_BIN);}
function updateStoreStatus($id,$status){
$db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
$q=$db->prepare('UPDATE Stores SET status=?, updated=? WHERE storeID=?');
$date=date("Y-m-d H:i:s");
$q->bind_param("isi",$status,$date,$id);
$q->execute();
$q->close();
return 1;
}
function emptyStores(){
$db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
$q=$db->prepare('DELETE FROM Stores WHERE status='.RECYCLING_BIN);
$q->execute();
$q->close();
return 1;
}
function deleteStore($id){
$db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
$q=$db->prepare('DELETE FROM Stores WHERE storeID=?');
$q->bind_param("i",$id);
$q->execute();
$q->close();
return 1;
}
function insertStore($store){
$db = new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
$store->created=date("Y-m-d H:i:s"); //overwrite dates
$store->updated=$store->created;
if($q = $db->prepare('INSERT INTO Stores (name,contact,address,phone,fax,email,webpage,latitude,longitude,status,created,updated) values (?,?,?,?,?,?,?,?,?,?,?,?)')){
$q->bind_param("sssssssssiss",
$store->name,
$store->contact,
$store->address,
$store->phone,
$store->fax,
$store->email,
$store->webpage,
$store->latitude,
$store->longitude,
$store->status,
$store->created,
$store->updated);
$q->execute();
$q->close();
}
else{
printf($db->errno);
exit();
}
$q=$db->prepare('SELECT storeID FROM Stores WHERE name=? AND created=?');
$q->bind_param("ss",$store->name,$store->created);
$q->execute();
$q->bind_result($sid);
$q->fetch();
$q->close();
if(strlen($sid)>0) return $sid;
else return ERROR_DEFAULT;
}
//PRE-CONDITION: email, password, billingID, groupID must exist
function updateStore($store){
$db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
//BEGIN ERROR CHECKING -------------------------------
//END ERROR CHECKING ---------------------------------
$store->updated=date("Y-m-d H:i:s"); //overwrite dates
$q=$db->prepare('UPDATE Stores SET name=?, contact=?, address=?, phone=?, fax=?, email=?, webpage=?, latitude=?, longitude=?, status=?, updated=? WHERE storeID=?');
$q->bind_param("sssssssssisi", $store->name,$store->contact,$store->address,$store->phone,$store->fax,$store->email,$store->webpage,$store->latitude,$store->longitude, $store->status, $store->updated,$store->storeID);
$q->execute();
$q->close();
$q=$db->prepare('SELECT storeID FROM Stores WHERE name=? AND created=?');
$q->bind_param("ss",$store->username,$store->created);
$q->execute();
$q->bind_result($sid);
$q->fetch();
$q->close();
if(strlen($sid)>0) return $sid;
else return ERROR_DEFAULT;
}
function getStore($id){
$db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
$q=$db->prepare('SELECT storeID,name,contact,address,phone,fax,email,webpage,latitude,longitude,status,created,updated FROM Stores WHERE storeID=?');
$q->bind_param("i",$id);
$q->execute();
$q->bind_result($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
$s=NULL;
if($q->fetch()){
$s=new Store($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
}
$q->close();
return $s;
}
function getStoreCount($filter=NULL){
$db=new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
$sql='SELECT COUNT(*) FROM Stores';
if($filter!=NULL) $sql.=" WHERE ".$filter;
$q=$db->prepare($sql);
$q->execute();
$q->bind_result($count);
$q->fetch();
$q->close();
return $count;
}
function getStores($filter=NULL,$order=NULL,$start=0,$limit=10){
$db = new mysqli(DB_HOST, DB_ADMIN, DB_PWORD, DB_NAMES);
$sql='SELECT storeID,name,contact,address,phone,fax,email,webpage,latitude,longitude,status,created,updated FROM Stores';
if($filter!=NULL) $sql.=" WHERE ".$filter;
if($order!=NULL) $sql.=" ORDER BY ".$order;
if($limit>0) $sql.=' LIMIT '.$start.','.$limit;
$q=$db->prepare($sql);
$q->execute();
$q->bind_result($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
$s=NULL;
while($q->fetch()){
if($s==NULL) $s=array();
$store=new Store($storeID,$name,$contact,$address,$phone,$fax,$email,$webpage,$latitude,$longitude,$status,$created,$updated);
$s[]=$store;
}
$q->close();
return $s;
}
?>
defines.php
<?php
define("CHARSET","utf-8");
define("BASE_URL","http://MYURL/");
define("SITE_NAME","MY SITE Maps Manager");
define("SITE_TITLE","Default Title");
define("GOOGLE_ANALYTICS_TRACKER_ID","");
define("RECAPTCHA_PUBLIC_KEY","");
define("RECAPTCHA_PRIVATE_KEY","");
define("PRIVATE_KEY","");
define("RECYCLING_BIN",-1);
define("DEFAULT_STATUS",0);
define("VERIFIED",1);
define("UNVERIFIED",2);
define("ERROR_DEFAULT",-1);
define("DB_HOST","localhost");
define("DB_ADMIN","GODADDY_DBUSER");
define("DB_PWORD","MYPASSWORD");
define("DB_NAMES","DATABASENAME");
?>