My page does not connect to my database

1

I try to connect to my database in the following way:

mysql_connect($server, $user, $pass);
mysql_select_db($db);

I know that mysql is obsolete but how I use an old version xampp should work. However, my page never ends up loading and is always waiting.

Start the session as follows:

<?php
@session_start();
if (isset($_POST['user']) && !empty($_POST['user']) && isset($_POST['pass']) && !empty($_POST['pass'])) {

    include_once("includes/config.php");

    if ($admin_user == $_POST['user']) {
        if ($admin_password == sha1($_POST['pass'])) {
            $_SESSION['login'] = true;
            header("Location: stats.php");
            exit();
        }
    }
}
?>

Could someone say how can I debug this code to get it started correctly?

    
asked by Sergio Ramos 01.05.2018 в 13:55
source

2 answers

0

Use the function error_reporting (E_ALL), I recommend you put an exit () after the mysql_connect to know if it is there where it is waiting.

    
answered by 02.05.2018 в 01:11
0

I recommend you use mysqli

file conexion.php

<?php

  DEFINE ('DB_USUARIO','user');
  DEFINE ('DB_CLAVE','pass');
  DEFINE ('DB_HOST','localhost');
  DEFINE ('DB_NOMBRE','database');
   $con = mysqli_connect(DB_HOST,DB_USUARIO,DB_CLAVE,DB_NOMBRE);
   mysqli_set_charset($con, "utf8");
 ?>

simply in your external files send it to call as follows:

include('conexion.php');

If you need to make a query with the following:

mysqli_query($con,"INSERT INTO...");
    
answered by 02.05.2018 в 01:49