I want to fetch mysql results

Discussion in 'PHP' started by sonu21, Jul 11, 2012.

  1. #1
    Hi Guys,I need your help.I have login code but it is with defined user name & password.I need to fetch details from DB.Currently it is showing successful login only if username= "demo" & password="demo" .I want to authenticate user.

    Below is the code :

    <?php

    $is_ajax = $_REQUEST['is_ajax'];
    if(isset($is_ajax) && $is_ajax)
    {
    $username = $_REQUEST['username'];
    $password = $_REQUEST['password'];

    if($username == 'demo' && $password == 'demo')
    {
    echo "success";
    }
    }

    ?>

    Thanks in Advance!
     
    Last edited: Jul 11, 2012
    sonu21, Jul 11, 2012 IP
  2. eritrea1

    eritrea1 Active Member

    Messages:
    182
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    70
    #2
    Currently it is showing successful login only if username= "demo" & password="demo"

    BECAUSE of this code -- > if($username == 'demo' && $password == 'demo')
    { echo "success"; }


    That is not how you request login details from DB. Because, You have already instructed PHP to display succsess message if only $username ='demo' && $password=='demo'.

    The code is only showing you, what you ordered it.

     
    eritrea1, Jul 11, 2012 IP
  3. sonu21

    sonu21 Member

    Messages:
    102
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Thanks for your reply.I know this.But,I want to authenticate user with his details from DB.
     
    sonu21, Jul 11, 2012 IP
  4. eritrea1

    eritrea1 Active Member

    Messages:
    182
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    70
    #4
    Your question is not clear, or I am too newbie for this.
     
    eritrea1, Jul 11, 2012 IP
  5. sonu21

    sonu21 Member

    Messages:
    102
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #5
    No Problem Bro.Thanks for your help though!
     
    sonu21, Jul 11, 2012 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    Use a SELECT query into the database using the username and password supplied. (Do it this way to learn how it works, not for a live site.) Then check the result of the query. If there's one, and only one, row returned, the given username and password pair exist in a record in the database. If there's no record, you don't have that combo. If there's more than one record (assuming you check that when a new user registers, and don't allow the same username to register twice), someone is trying to hack the site, or your database is corrupt.

    Once that works, use whatever method you prefer to prevent SQL injection attacks (see this page) before going live.
     
    Rukbat, Jul 13, 2012 IP