JQUERY & php post 500 error (internal server error)

I am stuck with a bug in a webapp I am developing, I am sure this is a fairly simple error.

Whenever I run this code on the net, debumuger chromium returns me this error:

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

      

  • PHP server is working correctly, phpinfo () returns all information correctly.
  • The web server is Apache.
  • Iptables is completely open source and I just use it on my local network.
  • Resolving the whole file in the network root 755.

Here is a snippet of the JQUERY, js file "

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 comes back over and over again:

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

      

0


source to share


2 answers


To show errors on a page:

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

      

First, the display of errors on the page itself will turn on, instead of generating a 500 error.

Second, make sure all bugs are reported. This includes notifications.

Council. Write code that doesn't even trigger one notification.

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 using the following repositories if you want to access 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

      

For installation:

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 that after installing the repositories, you edit them and set them to 0 so that you can only selectively use them the way you should.

yum --enablerepo=remi,epel install whatever

      

+10


source


It looks like the mysqli extension is not installed or enabled. Check your php.ini for string extension=mysqli.so

, otherwise enable it or install withsudo apt-get install php5-mysql



+6


source







All Articles