Hello fellow programmers,
I have made a function that looks up the database if a login already exists and then returns either true or false, here is the body of this function:
public static function loginExiste($login)
{
$cnx = new GestionBD("localhost", "fnak", "root", "");
$login = mysql_real_escape_string($login);
$ret = $cnx->execRequete("SELECT COUNT(*) FROM clients WHERE Client_Login = '".$login."'");
$col = mysql_fetch_array($ret);
echo 2;
if ($col[0] > 0)
{
echo 3;
return true;
}
else
{
echo 4;
return false;
}
}
and here is how I call this function:
echo 1;
if (!ExecRequete::loginExiste($_POST['login']))
{
echo 5;
/*
echo '<center><p style="color:red;">
Erreur: Login existe déjà
</p></center>';
exit();
*/
}
echo 6;
Now as you can see, I have some echo statements scattered around to see how the execution is flowing. The result I get every single time is this:
if the login exists: 123 if it doesn't exist: 124
From the result I see that the script stops the execution right after the return statement. normally It should be like this:
1236 or 12456
The worst part about this is that it happened to me during an exam, that made me very upset as it doesn't make sense at all. The debugging lost me so much time that I couldn't finish the other easy parts..
Can anybody see why is this strange behavior happening here ?