0

I'm new here so I have some question. I'm developing a web site, but there is some problem. I have map with tags, that onclick invokes a function "getObject(this.alt)".

function getObjects(object){
console.log(object);
$.get("/sites/map/objects.php?t="+object, function(data) {
  $('#answer').html(data);
});

It executes script object.php were t= area tags alt attribute, the objects.php connects to MySql and returns objects row, but I get this kind of error:

GET http://some-site.com/sites/map/objects.php?t=some_object 500 (Internal Server Error) jquery-latest.js:8706

Can you please help me? :)

This is the PHP code. Object is alt atribute from area tag in HTML file. It gets this alt and from that returns DB row with this alt name.

<?php
$object = $_GET['t'];
echo $object;
$con=mysqli_connect("server_adr","username","password","db_name");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$con->set_charset("utf8");
if($object!='all'){
$result = mysqli_query($con,"SELECT * FROM map WHERE `city`='$object' ORDER BY tips");
}
else{
$result = mysqli_query($con,"SELECT * FROM map ORDER BY tips"); 
}
$old_tips = '';
$old_city = ''; 
while($row = mysqli_fetch_array($result))
  {
  $tips = $row['tips'];
  $city = $row['city'];
  if($old_tips!=$tips){
      echo '<strong>'.$tips.'</strong><br>';
  }
  if($old_city!=$city){
      echo $row['city'] . '<br>';
  }
  echo $row['title'] . ' - <a href="'.$row['web'].'">' . $row['web']. '</a>';
  echo "<br>";
  $old_tips = $row['tips'];
  $old_city = $row['city'];
  }
?>

And the WEB server info:

  • Apache/2.2.21 (FreeBSD) mod_ssl/2.2.21 OpenSSL/0.9.8q DAV/2 PHP/5.3.8 with Suhosin-Patch SVN/1.7.1
  • MySQL client version: 5.1.59
  • PHP extension: mysql
veiss
  • 79
  • 2
  • 10

3 Answers3

1

mysqli_connect throws exception if mysqli module not installed or enabled. You'd activate this module in the php extions file

OR if your database is a mysql database and not mysqli, try to change from mysqli to mysql in your php code file

Bellash
  • 7,560
  • 6
  • 53
  • 86
  • The PHP extension shows mysql, but when I change mysqli to mysql nothing changes. – veiss Apr 14 '14 at 10:21
  • No! What you need to do in your PHP extentions file is TO UNCOMMENT THE LINE WHERE `mysqli` is. OR if you are using a mysql database, the function to use in your php file is `mysql_...` instead of `mysqli_...` – Bellash Apr 14 '14 at 10:26
  • Sorry, that was what I ment. Extension shows `mysql` and the changes I made in my php file. So now I something did that mysql_error() shows `Lost connection to MySQL server at 'reading initial communication packet', system error: 61` I think better than `Internal Server Error`. I cant get to server configuraton, is there another way to resolve this? – veiss Apr 14 '14 at 11:06
  • Cheking out `mysql_connect()` I have new error. `Access denied for user 'user'@'multisite' (using password: YES)` Why multisite? And this `user` has `WRITE` `READ` and all needed premissions. Whats wrong with my SQL? – veiss Apr 14 '14 at 11:22
  • what is you dbms? Are you using `mysql` or `mysqli` ? – Bellash Apr 14 '14 at 13:26
  • PHP extension: `mysql` – veiss Apr 14 '14 at 13:29
  • Done, I will post my answer tomorrow. Thanks everybody for help :) – veiss Apr 14 '14 at 13:35
0

Your error is on the php.

Add this to the top of your php script:

ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");

Then check the log:

tail -f /tmp/php-error.log
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

So I solved problem like this. Cheked the PHP extension, changed mysqli_... to mysql_... Cheked the SQL user privilegies and changed them to be suitable to my problem. And I had database address written "localhost" because it runs on other server, not mine but when given to mysql_connect() the address like in IP, then the connection established right. And whola it worked, thanks everybody for help. :)

Now it looks something like this:

$connection = mysql_connect("db_addr","sql_user","password");
// Check connection
if (!$con)
{
    die ("Could not connect: " . mysql_error());
}
echo "Connection successfully <br>";

mysql_select_db("database_name");
mysql_set_charset('utf8' , $connection);
veiss
  • 79
  • 2
  • 10