[英]JQUERY & php post error 500 (server internal error)
I am stuck with an error in a webapp that I am developing, I am sure that it is quite basic error. 我在开发的Web应用程序中遇到错误,我确信这是非常基本的错误。
Whenever I run this code in the web the chromium debbuger return me this error: 每当我在网上运行此代码时,chrome调试器都会向我返回此错误:
POST http://my_ip/server_wrapper.php 500 (Internal Server Error)
Here is the JQUERY, js file fragment" 这是JQUERY,js文件片段”
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文件:
<?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);
}
?>
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. 首先,将在页面本身上启用错误显示,而不是生成500错误。
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: 查找PHP错误日志文件:
grep error_log /etc/php.ini
grep ^error_log /etc/php.ini
To install MySQL on RedHat family servers: 要在RedHat系列服务器上安装MySQL:
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. 如果您想访问最新的PHP版本,建议您使用以下存储库。
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. 确保安装回购协议后,将其编辑并设置为0,以使您只能根据需要选择性地使用它们。
yum --enablerepo=remi,epel install whatever
It looks like the mysqli extension is not installed or enabled. 似乎未安装或启用mysqli扩展名。 Check your php.ini for the line
extension=mysqli.so
, otherwise enable it or install it with sudo apt-get install php5-mysql
检查您的php.ini中是否存在
extension=mysqli.so
这行,否则启用它或使用sudo apt-get install php5-mysql
安装它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.