Problems with PHP and SQL (expects parameter 1 to be sqli) [duplicated]

0

I was trying to open my .php file from the localhost and I got the following errors:

First error:

  

Warning: mysqli_select_db () expects parameter 1 to be mysqli, string given in C: \ xampp \ htdocs \ conexion.php on line 8

Code of the first error:

<?php
define('DB_SERVER','localhost');
define('DB_NAME','*****');
define('DB_USER','*****');
define('DB_PASS','*****');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
mysqli_select_db(DB_NAME,$con);
?>

Second error:

  

Notice: Undefined index: user in C: \ xampp \ htdocs \ index.php on line 4   Please fill in all fields.

Code of the second error:

<?php
session_start();
include_once "conexion.php";
    if($_POST['usuario'] == '' or $_POST['password'] == '' or $_POST['repassword'] == '')

    {
        echo 'Por favor llene todos los campos.';
    }
    else
    {
        $sql = 'SELECT * FROM usuarios';
        $rec = mysql_query($sql);
        $verificar_usuario = 0;

        while($result = mysql_fetch_object($rec))
        {
            if($result->usuario == $_POST['usuario'])
            {
                $verificar_usuario = 1;
            }
        }

        if($verificar_usuario)
        {
            if($_POST['password'] == $_POST['repassword'])
            {
                $usuario = $_POST['usuario'];
                $password = $_POST['password'];
                $sql = "INSERT INTO usuarios (usuario,password) VALUES ('$usuario','$password')";
                mysql_query($sql);

                echo 'Usted se ha registrado correctamente.';
            }
            else
            {
                echo 'Las claves no son iguales, intente nuevamente.';
            }
        }
        else
        {
            echo 'Este usuario ya ha sido registrado anteriormente.';
        }
    }
    
asked by sergio 19.05.2018 в 12:43
source

1 answer

0
  

Warning: mysqli_select_db () expects parameter 1 to be mysqli, string given in C: \ xampp \ htdocs \ conexion.php on line 8

<?php
define('DB_SERVER','localhost');
define('DB_NAME','*****');
define('DB_USER','*****');
define('DB_PASS','*****');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
mysqli_select_db($con, DB_NAME);
?>

mysqli_select_db (connection, database_name) You had the parameters of the function upside down, try to see how it is.

  

Notice: Undefined index: user in C: \ xampp \ htdocs \ index.php on line 4 Please fill in all the fields.

Regarding this error, you are saying that the $ _POST superglobal does not contain the 'user' key, so it enters the if and shows you the echo message. Greetings.

    
answered by 19.05.2018 / 12:51
source