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

  • SEARCH
  • Home
  • 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 7520803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:07:52+00:00 2026-05-30T02:07:52+00:00

We have a form with php post redirecting communication to database and We’d like

  • 0

We have a form with php post redirecting communication to database and We’d like if there would have an easy method to detect if failed logins were doubt to username no exists or password dont match. say each error as separate option.

<form id="form1" action="doLogin.php" method="post">
    <div id="border2">
    <table class="table_text" cellpadding="2" cellspacing="0" border="0">
        <tr>
            <td>Username:</td>
            <td><input type="text" name="username" class="input" /></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="password" class="input" /></td>
        </tr>
        <tr>
            <td colspan="2" align="right"><a target="_new" href="register.php">Register</a><input id="login_button" type="submit" name="submit" value="Login" class="button" /></td>
        </tr>
    </table>
        </div>
</form>
  • 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-30T02:07:54+00:00Added an answer on May 30, 2026 at 2:07 am

    Try this

    function protect($string){
        $string = trim(strip_tags(addslashes($string)));
        return $string;
    }
    
    if($_POST['submit']){
        $username = protect($_POST['username']);
        $password = protect($_POST['password']);
        if(!$username || !$password){
            //if not display an error message
            echo "<script> alert('No data entered') </script>";
            echo "<script type='text/javascript'>document.location.href='index.php';</script>";
    
        }else{
            //if the were continue checking
            //select all rows from the table where the username matches the one entered by the user
            $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
            $num = mysql_num_rows($res);
            //check if there was not a match
            if($num == 0){
                //if not display an error message
                echo "<script> alert('User does not exist') </script>";
                echo "<script type='text/javascript'>document.location.href='index_spa.php';</script>";
    
            }else{
                //if there was a match continue checking
                //select all rows where the username and password match the ones submitted by the user
                $res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."'");
                $num = mysql_num_rows($res);
                //check if there was not a match
                if($num == 0){
                    //if not display error message
                    echo "<script> alert('Invalid Password') </script>";
                    echo "<script type='text/javascript'>document.location.href='index.php';</script>";
                }else{
                    //if there was continue checking
                    //split all fields fom the correct row into an associative array
                    $row = mysql_fetch_assoc($res);
                    //check to see if the user has not activated their account yet
                    if($row['active'] != 1){
                        //if not display error message
                        echo "<script> alert('Your account " . $username . " is not activated yet.') </script>";
                        echo "<script type='text/javascript'>document.location.href='index_spa.php';</script>";
    
                    }else{
                        //if they have log them in
                        //set the login session storing there id - we use this to see if they are logged in or not
                        $_SESSION['uid'] = $row['id'];
                        //show message
                        echo "<script type='text/javascript'>document.location.href='index.php?u=" . $username . "';</script>";
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that looks like: <form action=search.php method=post> <fieldset> <label for=level_one>Main category</label>
i have a web form who send post variables like: <form action=teacher.php method=post> <input
I have regular form like this. <form action=/domainchecker.php method=post> <input type=text name=domain size=20> <fieldset>
If I have a html form like the following: <form name=statusForm action=post.php method=post enctype=multipart/form-data>
I have a form like below on my index page: <form action=send.php method=POST> <b>Your
I have an HTML form: <form action='process.php' method='post'> <input type='checkbox' name='check_box_1' /> Check me!<br>
I have this form: <form action=contact.php method=post id=contactform> <ol> <li> <label for=name>First Name *
I have this form: <form action=after.php method=post id=divulgacao> <div style=float: left;width: 195px; margin-right: 10px;>
I have a form in index.php <?php echo '<form action=update_act.php method=POST>'; echo '<input type=submit
Let say that I have the form below: <form action=sendMessage.php method=post> <label>Subject</label><input type=text></input> <label>Message</label><input

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.