lundi 25 janvier 2016

check if user already exists in mysql with php please help me [duplicate]

This question already has an answer here:

I am using following code which is not working for me. pretty stuck on trying to prevent the user from registering if the username exists. Here is my code:

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];
$score = $_REQUEST['score'];
$rank = $_REQUEST['rank'];

if($username ==  '' || $password == '' || $email == ''){
echo ' please fill values';
}else{
    $connection = connectToDatabase();
    $sql = "SELECT * FROM task WHERE username='$username' OR email='$email'";

    $check = mysqli_fetch_array(mysqli_query($connection,$sql));
    if(isset($check)){
        echo 'username or email already exist';
    }else{

$result = mysqli_query($connection, "INSERT INTO task VALUES (0, '$username', '$password', '$email', '$score', '$rank')");

        if(mysqli_query($connection,$result)){
            echo 'successfully registered';
        }else{
            echo 'oops! Please try again!';
        }
    }
mysqli_close($connection);

please help me...

Aucun commentaire:

Enregistrer un commentaire