0

The following is my php code with SQL.

$con=mysqli_connect("localhost","root","","ananas");
if (mysqli_connect_errno()) {
  echo json_encode(mysqli_connect_errno());
}

$sql = "SELECT venues.*, (6371*acos(cos(radians(".$curr_lat."))*cos(radians(venues.lat))*cos(radians(venues.longi)-radians(".$curr_longi."))+sin(radians(".$curr_lat."))*sin(radians(venues.lat)))) AS radius    
            FROM venues 
            HAVING radius < ".$radius ;
    $result = mysqli_query($con,$sql);
    if (!$result) {
        die("Error running $sql: " . mysql_error());
    }

I ve verified all the database, table names and column names I wanna extract are working fine. Even same code was working fine before I reinstalled xampp and reset my phpmyadmin with DB.

But now even with older setting, i.e. after restoring the same database, tables, username & password as before I get an error. It shows error when I try calling it from JS file using xmlhttprequest object.

The following is my JS function for calling the PHP file through xmlhttp

function loadXMLDoc(city)
{

var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        myData= eval("(" + xmlhttp.responseText + ")");
        console.log(myData);
        $('#header_bottom_wrapper .nav span').html(city);
        mapMarkers(myData);
        map.fitBounds(circle.getBounds());
        loadPlaces();
        getVenues();
    }
  else{
    alert(status+", "+exception);
  }
  }
xmlhttp.open("GET","./content/sessionVariableChange.php?city="+city+"&curr_lat="+curr_lat+"&curr_longi="+curr_longi+"&radius="+radius+"&capacity="+capacity,true);
xmlhttp.send();
}

sessionVariableChange.php is the name of php file where I access my database.

When I try to run the file, I get the following error in my console. **Uncaught SyntaxError: Unexpected token ) **

Any help would be helpful. Thanks in advance.

Debasish Kanhar
  • 1,123
  • 2
  • 15
  • 27
  • Dont you miss a `GROUP BY` in your SQL? The query might be valid with `HAVING` and without `GROUP BY` but does it really do what you want? Do you Need a `WHERE` instead? [see here](http://stackoverflow.com/questions/6924896/having-without-group-by) on that Topic, too) – Benvorth Oct 13 '14 at 20:01
  • Thanks for the comment Benni. No I didnt miss GROUP BY in my SQL. This statement was working perfectly fine till some days back. Now all I did was reinstall script after formatting and it shows error. It used to give me the required results also. – Debasish Kanhar Oct 13 '14 at 20:18
  • Do a) Check if you can run the query directly on the database. If this works well check b) the port of your MySQL Installation and if you use that port in your php connection to MySQL (Default is 3306). If this is set-up correctly it is c) a sytax error in php. But without further Information it is hard to track for us... – Benvorth Oct 13 '14 at 20:28

0 Answers0