简体   繁体   English

GET方法返回500内部服务器错误

[英]GET method returns 500 Internal server error

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)". 我有带标签的地图,该onclick会调用函数“ 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: 它执行脚本object.php是t =区域标签alt属性,objects.php连接到MySql并返回对象行,但是出现这种错误:

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. 这是PHP代码。 Object is alt atribute from area tag in HTML file. 对象是HTML文件中区域标签的全部属性。 It gets this alt and from that returns DB row with this alt name. 它获取此alt,并从中返回具有此alt名称的数据库行。

<?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: 和WEB服务器信息:

  • 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 具有Suhosin-Patch SVN / 1.7.1的Apache / 2.2.21(FreeBSD)mod_ssl / 2.2.21 OpenSSL / 0.9.8q DAV / 2 PHP / 5.3.8
  • MySQL client version: 5.1.59 MySQL客户端版本:5.1.59
  • PHP extension: mysql PHP扩展名:mysql

mysqli_connect throws exception if mysqli module not installed or enabled. 如果未安装或未启用mysqli模块,则mysqli_connect引发异常。 You'd activate this module in the php extions file 您可以在php extions文件中激活此模块

OR if your database is a mysql database and not mysqli, try to change from mysqli to mysql in your php code file 或者如果你的数据库是MySQL数据库,而不是mysqli的,尝试从改变mysqlimysql在你的PHP代码文件

Your error is on the php. 您的错误在php上。

Add this to the top of your php script: 将此添加到您的php脚本的顶部:

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

Then check the log: 然后检查日志:

tail -f /tmp/php-error.log

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. 检查了PHP扩展名,将mysqli_...更改为mysql_... _...。检查了SQL用户权限并将其更改为适合我的问题。 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. 而且我将数据库地址写为“ localhost”,因为它在其他服务器上运行,而不是在我的服务器上运行,但是当给mysql_connect()该地址就像在IP中一样,则连接正确。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM