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 7046807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:41:41+00:00 2026-05-28T02:41:41+00:00

I have a problem with checking if the username exist. It works if it

  • 0

I have a problem with checking if the username exist. It works if it does exist. But if the username doesn’t exist it just send me to an empy page. It seems that it doesn’t go to the next statement.

Here the code

<?php
if($_POST[username]  && $_POST[email] &&  isset($_POST[password])  && isset($_POST[password2])  && $_POST[password] == $_POST[password2])
{
    include ('*********'); /my connection to the database
    $username = $_POST[username];

            //check with the registred members
    $query2 = "SELECT * FROM registredMembers WHERE username='$username'"; 
    $result2 = mysql_query($query2, $conn) or die(mysql_error());
    $existing_users = mysql_num_rows($result2) or die(mysql_error());

            // check with the temporarly members, waiting to activate account
    $query3 = "SELECT * FROM tempMembers WHERE username='$username'"; 
    $result3 = mysql_query($query3, $conn) or die(mysql_error());
    $existing_users2 = mysql_num_rows($result3) or die(mysql_error());

    if($existing_users != 0 && $existing_users2 != 0) 
    {
        echo "<div id='msg'>Användarnamnet är upptaget</div>";
    }

    else 
    {   
        $confirmCode = md5(uniqid(rand()));
        $query = "INSERT INTO tempMembers VALUES ('$confirmCode', '$_POST[username]', '$_POST[email]', '$_POST[password]')";
        $result = mysql_query($query, $conn) or die(mysql_error());

        if($result)
        {
            $to = $_POST[email];
            $subject = utf8_decode("Här är din bekräftelselänk");
            $header = utf8_decode("Från Adib Haider (PHP-Projekt)");
            $message = "Din bekräftelselänk \r\n";
            $message.= "Klicka på länken för att aktivera ditt konto \r\n";
            $message.= "http://labb.vgy.se/~adibbinhar/blogg/confirmation.php?passkey=$confirmCode";
            $sentmail = mail($to, $subject, utf8_decode($message), $header);

            if($sentmail)
                echo "<div id='msg'>Aktiveringsmailet har skickat till din e-postadress</div>";
            else 
                echo "<div id='msg'>Aktiveringsmailet skickades inte</div>";
        }

        else
            echo "<div id='msg'>Testa igen</div>";
    }   
}

else
    echo "<div id='msg'>Prova igen</div>";

the text is on swedish hope you can live with that 😛

  • 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-28T02:41:41+00:00Added an answer on May 28, 2026 at 2:41 am

    /I went through your code and added a little protection from injections as well as hopefully fixing your problem.
    Like Joachim said, when the mysql_num_rows didn’t return anything, you die() the script.

    This is the code I whipped together, you need to check the tables are correct and like, as this was a real quick run through:

        <?php
        if($_POST['username']  && $_POST['email'] &&  isset($_POST['password'])  && isset($_POST['password2'])  && $_POST['password'] == $_POST['password2'])
        {
            include ('*********'); //my connection to the database
            $username = mysql_real_escape_string($_POST['username']);
            $email = mysql_real_escape_string($_POST['email']);
            $password = mysql_real_escape_string($_POST['password']);
    
            //check with the registred members
            $query1 = "SELECT * 
                         FROM registredMembers as users, 
                              tempMembers as temp
                         WHERE users.username = '$username' 
                            OR temp.username ='$username'";
    
            $check = mysql_query($query1, $conn) or die(mysql_error());
    
            if(mysql_num_rows($check) < 1)
            {
                $confirmCode = md5(uniqid(rand()));
                $query = "INSERT INTO tempMembers (`confirmCode`, `username`, `email`, `password`) VALUES ('$confirmCode', '$username', '$email', '$password')";
                $result = mysql_query($query, $conn) or die(mysql_error());
    
                if($result)
                {
                    $to = $email;
                    $subject = utf8_decode("Här är din bekräftelselänk");
                    $header = utf8_decode("Från Adib Haider (PHP-Projekt)");
                    $message = "Din bekräftelselänk \r\n";
                    $message.= "Klicka på länken för att aktivera ditt konto \r\n";
                    $message.= "http://labb.vgy.se/~adibbinhar/blogg/confirmation.php?passkey=$confirmCode";
                    $sentmail = mail($to, $subject, utf8_decode($message), $header);
    
                    if($sentmail)
                    {
                        echo "<div id='msg'>Aktiveringsmailet har skickat till din e-postadress</div>";
                    }
                    else
                    { 
                        echo "<div id='msg'>Aktiveringsmailet skickades inte</div>";
                    }
                }
    
                else
                {
                    echo "<div id='msg'>Testa igen</div>";
                }
            }
    
            else
            {
                echo "<div id='msg'>Användarnamnet är upptaget</div>";
            }   
        }
        else
        {
            echo "<div id='msg'>Prova igen</div>";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem with this registration form, im checking the password and username,
I have a problem checking a select that look like this: <select name=recipe[category]> <option
My problem involves checking if I have a valid database connection before reading from
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with fancybox. I want to write a function that will run
I have checked the user name availability. The problem is, even if the username
I have an ASP.NET page running in SSL and the checking happens in the
I have a routine that updates information on a web page. The page is
I have a sign-in-action-form page which accept username and password from sign-in-form. Now most
I have a problem on checking the text and string. public boolean Isequals(Object c){

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.