JQUERY& PHP的帖子错误500(服务器内部错误) [英] JQUERY & php post error 500 (server internal error)

查看:113
本文介绍了JQUERY& PHP的帖子错误500(服务器内部错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



每当我在web上运行这段代码时,我都会遇到一个错误,铬debbuger返回我这个错误:

pre $ POST http://my_ip/server_wrapper.php 500(内部服务器错误)




  1. PHP服务器正常工作,phpinfo()正确返回整个信息

  2. Web服务器是Apache。

  3. Iptables完全打开,我只是在LAN下使用它。


以下是JQUERY,js文件片段

  this.post = function(){
$ .post(server_wrapper.php,
{
_id:this.id,
_question:this.question,
_type:none
},
函数(数据,状态){
alert( DATA:+ data +status:+ status);
}
);
}

以下是php文件:

 <?php 

if(isset($ _ POST [_ question])&& isset($ _ POST [_ type])&& isset($ _ POST [_ id])){

$ question = $ _POST [_ question];
$ type = $ _POST [_ type];
$ id = $ _POST [_ id];

$ con = mysqli_connect(localhost,user,pass,database);

if(mysqli_connect_errno($ con)){
echo无法连接到数据库;
$ b $ else else {
mysqli_query($ con,INSERT INTO questions(id,question,type)VALUES('$ id','$ question','$ type')) ;
}

mysqli_close($ con);
}
?>



编辑



这就是日志返回一遍又一遍:

  PHP致命错误:调用/var/www/server_wrapper.php中的未定义函数mysqli_connect 


解决方案



 <?php 
ini_set('display_errors','1');
ini_set('error_reporting',E_ALL);
?>

首先在页面上启用错误显示,而不是生成500错误。



其次将确保报告所有错误。这包括通知。



建议:编写甚至不会触发一个通知的代码。

要查找PHP错误日志文件:

  grep error_log /etc/php.ini 
grep ^ error_log /etc/php.ini

在RedHat上安装MySQL家庭服务器:

  yum install mysql.x86_64 
yum install mysql mysql-server
chkconfig --level 2345 mysqld on
服务mysqld start
mysqladmin -u root密码somepassword



 <$ c我建议您使用以下回购协议$ c> wget http://mirrors.coreix.net/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm 
wget http://rpms.famillecollet.com/enterprise/ remi-release-6.rpm

安装:

  rpm -Uvh remi-release  -  *。rpm epel-release  -  * .rpm 
/ bin / rm epel-release - *。noarch.rpm remi-release - * .rpm
perl -pi -e's / enabled = 0 / enabled = 1 / g'/etc/yum.repos.d /remi.repo
yum update(可选 - 不推荐,除非你知道你在做什么)
yum install yum-plugin-priorities

确保安装回购站后,您可以编辑它们并将其设置为0,这样您就可以选择性地使用它们了。

  yum --enablerepo = remi,epel安装任何


I am stuck with an error in a webapp that I am developing, I am sure that it is quite basic error.

Whenever I run this code in the web the chromium debbuger return me this error:

 POST http://my_ip/server_wrapper.php 500 (Internal Server Error) 

  1. PHP server works properly, phpinfo() returns the whole information correctly
  2. The web server is Apache.
  3. Iptables is completly open, and I am just using it under LAN.
  4. The permission of all the file in the web root directory are 755.

Here is the JQUERY, js file fragment"

this.post    = function () {
 $.post ("server_wrapper.php",
  {
   _id:          this.id,
   _question:    this.question,
   _type:        "none"
  },
  function (data, status) {
   alert ("DATA: " + data + " status: " + status);
  }
 );
}

Here is the php file:

<?php

if (isset($_POST["_question"]) && isset($_POST["_type"]) && isset($_POST["_id"])) {

$question = $_POST["_question"];
$type     = $_POST["_type"];
$id       = $_POST["_id"];

$con      = mysqli_connect ("localhost", "user", "pass", "database");

if (mysqli_connect_errno($con)) {
    echo "Failed to connecto to db";

} else {
    mysqli_query ($con, "INSERT INTO questions (id, question, type) VALUES ('$id','$question','$type')");
}

mysqli_close ($con);
 }
?>

EDIT

This is what the log return over and over again:

PHP Fatal error:  Call to undefined function mysqli_connect() in /var/www/server_wrapper.php

解决方案

To show errors on page:

<?php
    ini_set('display_errors', '1');
    ini_set('error_reporting', E_ALL);
?>

First will enable error display on the page itself instead of generating 500 error.

Second will make sure all errors are reported. This includes Notices.

Advice: Write code that does not even fire one notice.

To find the PHP error log file:

grep error_log /etc/php.ini
grep ^error_log /etc/php.ini

To install MySQL on RedHat family servers:

yum install mysql.x86_64
yum install mysql mysql-server
chkconfig --level 2345 mysqld on
service mysqld start
mysqladmin -u root password somepassword

I recommend you use the following repos if you want to have access to the latest PHP version.

wget http://mirrors.coreix.net/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

To install:

rpm -Uvh remi-release-*.rpm epel-release-*.rpm
/bin/rm epel-release-*.noarch.rpm remi-release-*.rpm
perl -pi -e 's/enabled=0/enabled=1/g' /etc/yum.repos.d/remi.repo
yum update (optional - not recommended unless you know what you are doing)
yum install yum-plugin-priorities

Make sure after you install the repos you edit them and set enabled to 0 that way you can use them selectively only as you should.

yum --enablerepo=remi,epel install whatever

这篇关于JQUERY&amp; PHP的帖子错误500(服务器内部错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆