Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    session help again!

    hi
    im trying to get sessions to work for my login page
    so far ive come up with the following query:
    Code:
    $user_name = $_POST["user_name"];
    $password = $_POST["password"];
    
    
    $query = "SELECT * FROM customers WHERE $user_name='$_POST[user_name]' AND $password='$_POST[password]'";
    $result = mysql_query($query, $connection) or die(mysql_error());
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    //if ($u_user_id == $row['user_name'] AND $u_password == $row['password']){
    
    if($result=="1") {
            $_SESSION[$user_name]=$_POST[user_name] && $_SESSION[$password]=$_POST[password]; echo "Hello $_SESSION[$user_name], you're logged in";
    
    }
    else  { echo "Thou art imposter!";
    but it dont even let me log anyone in at the moment.
    my login page works fine wen i wasnt trying to include sessions but now ive changed it to include sessions it doesnt work
    i get the error:

    Unknown column 'pv22' in 'where clause'

    pv22 should be the password that should be accepted

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you sure you want to do this
    PHP Code:

    $user_name 
    $_POST["user_name"];
    $password $_POST["password"];


    $query "SELECT * FROM customers WHERE $user_name='$_POST[user_name]' AND $password='$_POST[password]'"
    becuase all that will do is return everything from customers because $user_name has been set to $user_name

    so basically if the user name is set to MRMAN and password to 12341234. this is what the mysql statment will look like

    PHP Code:
    $query "SELECT * FROM customers WHERE MRMAN='MRMAM' AND 12341234='12341234'"
    i think you might want to do this
    PHP Code:

    $user_name 
    $_POST["user_name"];
    $password $_POST["password"];


    $query "SELECT * FROM customers WHERE user_name='$user_name' AND password='$password'"

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol ok thanks but it still wont let me login with correct details

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this

    PHP Code:
    if(mysql_num_rows($result)=="1") {
            
    $_SESSION[user_name]=$_POST[user_name] && $_SESSION[password]=$_POST[password]; 
    echo 
    "Hello $_SESSION[user_name], you're logged in";

    }
    else  { echo 
    "Thou art imposter!"; } 

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    wow!!
    ur a genius!! thank you so much!
    it works!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •