Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:09:35+00:00 2026-05-28T22:09:35+00:00

Hello fellow programmers, I have made a function that looks up the database if

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:09:36+00:00Added an answer on May 28, 2026 at 10:09 pm

    Finally ! I got where the error was ^^

    after restarting the function from scratch (like using if ($login == “a”) return true;) I found out that the problem was in the destructor of my GestionBD class that handles the connection with mysql. Because all the code in the function worked except at the very end on the return statement.

    What made me sure it was the destructor, is when I put $cnx = null; before my echo 2; and the execution stopped before the echo. Then I commented out the destructor and everything worked as needed. but I wondered what was wrong in my destructor…

    Here’s how it looked:

    function __destruct()
    {
        @mysql_close($this->$connexion);
    }
    

    Now, if anyone is familiar with OOP in PHP, he will spot the error right away.. the variable connexion is a member variable in the class. So when we refer to it with the pointer $this we needed to put it without $ (ahh I hate you $, I either forget you or put when you’re not needed :/ )

    the correct destructor is this:

    function __destruct()
    {
        @mysql_close($this->connexion);
    }
    

    but this mysql_close function is certainly not that well made, it doesn’t give any error message, not any exception, it just crashes the engine and leaves you wondering why ..

    Thank you all for your answers and help, it’s really appreciated 🙂 and an advice for everyone is that if you get any strange behavior or error messages at a simple return true; check all you local object’s destructors.. they may be guilty, and also USE PDO don’t use @ with mysql functions when debugging as it supresses any error output 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello fellow programmers. I have a SQL Server 2005 query that is taking a
Oh hello there, fellow SO members, I have a web service that returns XML
Hello fellow developers. I have previously made a facebook fan page with an iframe
Fellow JQuery hackers, hello :-) Suppose you have the following code: $('.links').click(function(){ //Do something
Hello fellow programmers I have been searching the internet for a few days now
Hello fellow C++ programmers. I have, what I hope to be, a quick question
Hello my fellow programmers, I have a problem (other than not knowing enough) I
Hello fellow computer people :) I have a shell script that I will use
hello fellow java developers. I'm having a bit of an issue here. I have
Hello fellow programmers, got a few problem here. I am adding a user control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.