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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:34:15+00:00 2026-05-29T11:34:15+00:00

I’m trying to make a form to login users into my webpage using mysql

  • 0

I’m trying to make a form to login users into my webpage using mysql db.

My page index.php has a form which posts to doLogin.php which checks user/pass from mysql database. Once a user is verified, I would like to show the username in a div to show they have been logged in.

index.php

JQuery

$document.ready(function() {

    $("#login_b").click(function() {
        var action = $("#form1").attr('action');
        var form_data = {
            username: $("#username").val(),
            password: $("#password").val(),
            is_ajax: 1
        };

        $.ajax({
        type: "POST",
                url: action,
                data: form_data,
                success: function(response)
                {
                    if(response == 'success')
                        alert( username + "Te logeaste correctamente","alert window");
                        document.location.href='index_spa.php';
                        $("#user_data").html( username + " online");
                    if(response == 'empty')
                        alert("No hay datos para validar","alert window");
                        $("#user_data").html("Campos vacios");
                        document.location.href='index_spa.php'
                    if(response == 'incorrect')
                        alert("Error en los datos introducidos","alert window");
                        $("#user_data").html("Datos incorrectos");
                        document.location.href='index_spa.php'
                    if(response == 'inactive')
                        alert("Cuenta no activada","alert window");
                        $("#user_data").html("La cuenta no está activada");
                        document.location.href='index_spa.php'
                }
            });
        return false;
    });
});

HTML

<div id="user_data"></div>
<div id="login_box">
    <form id="form1" action="doLogin.php" method="post">
        <div id="border">
            <table class="table_text" cellpadding="2" cellspacing="0" border="0">
                <tr>
                    <td>Usuario:</td>
                    <td>
                        <input type="text" name="username" class="input" />
                    </td>
                </tr>
                <tr>
                    <td>Clave:</td>
                    <td>
                        <input type="password" name="password" class="input" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="right">
                        <a class="link_login" target="_new" href="register.php">Registrarse</a>
                        &nbsp;&nbsp;&nbsp;
                        <input id="login_b" type="submit" name="submit" value="Login" class="button" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>

doLogin.php

<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
ob_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'winterfall', '14789632qwerty') or die(mysql_error());
$db = mysql_select_db('clientes', $con) or die(mysql_error());
//include out functions file giving us access to the protect() function made earlier
include "./functions.php";
//If the user has submitted the form
if($_POST['submit']){
    //protect the posted value then store them to variables
    $username = protect($_POST['username']);
    $password = protect($_POST['password']);
    //Check if the username or password boxes were not filled in
    if(!$username || !$password){
        //if not display an error message
        echo "empty";
    }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 "empty";
        }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 "incorrect";
            }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 "no active";
                }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 "success";
                    //update the online field to 50 seconds into the future
                    $time = date('U')+50;
                    mysql_query("UPDATE `users` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");
                    //redirect them to the usersonline page
                    //header('Location: usersOnline.php');
                }
            }
        }
    }
}
?>

please help me.

thank you

  • 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-29T11:34:16+00:00Added an answer on May 29, 2026 at 11:34 am

    Sorry if this seems like an odd question, but did your form work as you expected with doLogin.php before adding the JQuery functionality or is this the first time that you have tried it?

    The main problem that I see with your JQuery is that you do not have open and closing brackets within your if statements.

    So

    if(response == 'success')
        alert( username + "Te logeaste correctamente","alert window");
        document.location.href='index_spa.php';
        $("#user_data").html( username + " online");
    if(response == 'empty')
        alert("No hay datos para validar","alert window");
        $("#user_data").html("Campos vacios");
        document.location.href='index_spa.php'
    .....
    

    Should be

    if(response == 'success'){
        alert( username + "Te logeaste correctamente","alert window");
        document.location.href='index_spa.php';
        $("#user_data").html( username + " online");
    }
    if(response == 'empty'){
        alert("No hay datos para validar","alert window");
        $("#user_data").html("Campos vacios");
        document.location.href='index_spa.php'
    }
    .....
    

    You can also try using alert( response ) to see what you are getting back from the server.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.