php error with the server

0

I have this connection

conexion.php

<?php
   # Conexion con la Base de Datos
   $userdb = 'administrador';
   $passworddb = '123456789';
   $dbhost= 'dbserver';
   $dbname =   'sk_modular_divisiones';

?>

I have this query to fill a select

altura.php

<?php
/*Escoger Altura*/
require("conexion.php");
$link= mysqli_connect($dbhost,$userdb,$passworddb,$dbname);

  or die('No se pudo conectar: ' . mysql_error());
  mysql_select_db('sk_modular_divisiones') or die('No se pudo seleccionar la base de datos');
  $query= "SELECT DISTINCT sk_tipo FROM 'sk_standar' WHERE sk_tipo = 'ALTU-148' UNION SELECT DISTINCT sk_tipo FROM 'sk_standar' WHERE sk_tipo = 'ALTU-160'";
  $result = mysql_query($query)
            or die("Ocurrio un error en la consulta SQL");
            mysql_close();
  echo '<option value="0">Escoger altura</option>';
  while (($fila = mysql_fetch_array($result)) != NULL) {
    echo '<option value="'.$fila["sk_tipo"].'">'.$fila["sk_tipo"].'</option>';
  }
  //liberar resultador
  mysql_free_result($result);

  //Cerrar la conexión
  mysql_close($link);
?>

and I have this ajax

$(document).ready(function() {
     $.ajax({
       type: "POST",
       url: "php/altura.php",
       success: function(response)
       {
         $('.selector-elevation select').html(response).fadeIn();
       }
     });
    });

When I'm in local it works, but when I upload it to the server I get the following error. POST http://webserver/altura/php/altura.php 500 (Internal Server Error)

I do not know if I'm connecting badly to the database or the problem is ajax

    
asked by Eduard Zora 10.04.2017 в 22:06
source

2 answers

1

HTTP Error 500 Internal server error (Internal server error) It can occur by:

1 * Server software errors

2 * Programming errors:

check your PHP code well, that OR DIE should not go like this.

<?php
/*Escoger Altura*/
require("conexion.php");
$link= mysqli_connect($dbhost,$userdb,$passworddb,$dbname);

/*ESTO ESTA MAL >>> syntax error, unexpected 'or' (T_LOGICAL_OR)*/


  or die('No se pudo conectar: ' . mysql_error());
  mysql_select_db('sk_modular_divisiones') or die('No se pudo seleccionar la base de datos');
  $query= "SELECT DISTINCT sk_tipo FROM 'sk_standar' WHERE sk_tipo = 'ALTU-148' UNION SELECT DISTINCT sk_tipo FROM 'sk_standar' WHERE sk_tipo = 'ALTU-160'";
  $result = mysql_query($query)
            or die("Ocurrio un error en la consulta SQL");
            mysql_close();
  echo '<option value="0">Escoger altura</option>';
  while (($fila = mysql_fetch_array($result)) != NULL) {
    echo '<option value="'.$fila["sk_tipo"].'">'.$fila["sk_tipo"].'</option>';
  }
  //liberar resultador
  mysql_free_result($result);

  //Cerrar la conexión
  mysql_close($link);
?>

Try adding a IF :

  if ($link->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 

Instead of the OR DIE

<?php
/*Escoger Altura*/
require("conexion.php");
$link= mysqli_connect($dbhost,$userdb,$passworddb,$dbname);


  if ($link->connect_error) {
        die("Connection failed: " . $link->connect_error);
    } 

   mysql_select_db('sk_modular_divisiones') or die('No se pudo seleccionar la base de datos');
  $query= "SELECT DISTINCT sk_tipo FROM 'sk_standar' WHERE sk_tipo = 'ALTU-148' UNION SELECT DISTINCT sk_tipo FROM 'sk_standar' WHERE sk_tipo = 'ALTU-160'";
  $result = mysql_query($query)
            or die("Ocurrio un error en la consulta SQL");
            mysql_close();
  echo '<option value="0">Escoger altura</option>';
  while (($fila = mysql_fetch_array($result)) != NULL) {
    echo '<option value="'.$fila["sk_tipo"].'">'.$fila["sk_tipo"].'</option>';
  }
  //liberar resultador
  mysql_free_result($result);

  //Cerrar la conexión
  mysql_close($link);
?>

3 * Path errors in the scripts

4 * Errors in the configuration of the .htaccess

Let's see now:

Since the error only shows 500 you can use this command to see more specific errors:

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

Now, surely this " php / altura.php " is inside your server?

Have you cleared the cache to update the codes and files? control+shift+R

    
answered by 10.04.2017 / 22:21
source
0

If you are deploying on the same server (app and db), try this: $ dbhost = 'localhost';

    
answered by 10.04.2017 в 22:24