I am creating a simple registration page using IBM Db2 and PHP and all my data is saved in the Db2 database. However, I can't keep the constraint of already existing username. It is registering the user even if the username is already there in Db2. Also, it is logging in with any password entered!
I couldn't understand when the entries are shown in the database it means the data has found the right connection to the database. Then why it is not catching the constraints logic.
I just changed the MySQL functions in Db2 for PHP and there are some functions which are giving me error vibes like db2_exec()
and db2_fetch_assoc
.
$user_check_query= "SELECT * FROM users WHERE username ='$username'"
$result = db2_exec($db,$user_check_query);
$user = db2_fetch_assoc($result);
if(!empty($user)){ // Not empty mean database already exist this username
array_push($errors,"Username exists");
}