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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:13:59+00:00 2026-06-06T16:13:59+00:00

please, can you help me with this? I am a beginner in programming, so

  • 0

please, can you help me with this? I am a beginner in programming, so if it’s a stupid question, have a patience with me. Thank you.

I have index.php page with login form (username, password) and login.php with this part of a code:

<? if(!$_POST['username'] || !$_POST['password']){
$data['msg'] = 'All fields have to be filled!';
$data['success'] = false;}else{


mysql_query("   INSERT INTO log_access(user,ip,datetime)
                            VALUES(
                            '".$_POST['username']."',
                            '".$_SERVER['REMOTE_ADDR']."',
                            NOW()
                            )");

$row = mysql_fetch_assoc(mysql_query("SELECT id,login FROM users WHERE login='".$username."' AND pwd='".md5($password)."'"));

if($row['login'])
{
    $_SESSION['login'] = $row['login'];
    $_SESSION['id'] = $row['id'];

    $data['success'] = true;
    $data['redirect'] = "index.php";    
}
else 
{
    $data['success'] = false;
    $data['msg']='Wrong username or password!';
}}echo json_encode($data);?>

If i send empty field(s) in username or/and password, login.php return $data. But if i send filled fields, no data is comming back to index.php.
I have the following in index.php:

<script> 
    $(document).ready(function() 
            { 
                $('#frmLogin').submit(function() 
                { 
                    $.post('/scripts/login.php',{username: $('[name=username]').val(), password: $('[name=password]').val()}, function(data)
                        {
                            if(data.success)
                            {
                                $('#login-msg').html("Logged");
                            }
                            else
                            {
                                $('#login-msg').html(data.msg);
                            }
                        }
                        ,'json');
            return false; 
        }); 
            }); 
</script> 

I have the same problem if I put anything in the first condition, or before it (in login.php).
I don’t know, what i’m doing wrong 🙁

Thank for any help!
Washa

EDIT
SOLVED!
I have bad connection to the DB from the login script. Beginners mistake. Thanks for all replies.

  • 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-06-06T16:14:01+00:00Added an answer on June 6, 2026 at 4:14 pm

    Can you check Firebug’s console and see if the POST is happening and the response code is 200? you can also check what response is being retrieved.

    try calling a test.php with the following contents:

    <?
     if(!$_POST['username'] || !$_POST['password']){
    $data['msg'] = 'All fields have to be filled!';
    $data['success'] = false;
    }else{
    $data['success'] = true;
    $data['redirect'] = "index.php";  
    echo json_encode($_POST);
    }
    ?>
    

    Also check if the username and password are being passed in correctly by doing

    alert( $('[name=username]').val() + | + $('[name=password]).val()); 
    

    just above $.post.

    I checked your js by hardcoding username and password, they are working fine.
    its usually a good idea to divide and conquer. hardcode the input for your login.php page, and run it first, after its working then make your $_POST params as the input. this way you could prevent a lot of problems.

     ****Important Please ESCAPE ALL POST OR GET VARIABLES FOR MYSQL INSERT.
       Otherwise your scripts are vulnerable to SQL injections.
        ex: mysql_real_escape_string($_POST['username']);
        mysql_real_escape_string($_POST['password']);
    Please ignore if you are already doing this!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im a beginner to css, please can someone help me get this element to
can you please help me with this issue the String class does not have
Can anybody please help me with this as I have no idea why public
Can anyone please help me with this...I'm not very good with regular expressions and
can someone please help me. why does this return an error: Dim stuff As
Can anyone help me spot the problem on this PLEASE? I'm eternally grateful for
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
Can any one please help me solve this. I am resizing some flash object/embed
please can you help a jquery beginner out? I don't really know how to

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.