How to avoid two users repeating the same value in the database?

0
<?php

session_start (); 

include 'dbh.inc.php';
include 'login.inc.php'; 

$nuevonick = $_POST['nuevonick'];
$userid = $_SESSION['user_id'];

if ( isset($_POST['btnactualizar']) ) 

{


$sql = "SELECT * FROM users WHERE user_nick = '$nuevonick "; $result =         mysqli_query($conn, $sql);
$resultcheck = mysqli_num_rows ($result);

            if (!$resultcheck > 0) { header("Location: ../index.php?    cambio=invalido"); 
                                exit(); /* por si algo pasa*/}

                else
                {

$sql = "UPDATE users SET user_nick = '$nuevonick' WHERE user_id = '$userid'";
                mysqli_query ($conn, $sql); 
                $_SESSION['nick'] = $nuevonick; 
                header("Location: ../index.php?signup=success");                            
                exit ();
                }



}

else

{
echo 'error';
}

Until a few moments ago when I made this code it worked without problems, now no matter what, it allows to update the user to a nick that already exists in the database ... = S I do not understand

    
asked by Hoozuki 29.06.2018 в 03:27
source

0 answers