Login Problem with Mysql from PHP

Discussion in 'PHP' started by viron86, Nov 13, 2008.

  1. #1
    Login Problem with Mysql from PHP
    Hey Guys i have problem in coding of creating a login page with mysql database connectivity from php so anyone here kindly help me out
     
    viron86, Nov 13, 2008 IP
  2. alhelalat

    alhelalat Member

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    i can help you check you pm
     
    alhelalat, Nov 13, 2008 IP
  3. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #3
    
    <?
    session_start();
    //your db connection
    if(isset($_POST[username]) && isset($_POST[password])){
    $q = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST[username])."' AND password ='".md5($_POST[password])."' LIMIT 1");
    $n = mysql_num_rows($q);
    
    if($n == 0){
    echo "Wrong username and/or password";
    }else{
    $_SESSION[username] = $_POST[username];
    $_SESSION[password] = md5($_POST[password]);
    echo '<script>window.location=window.location</script>'; //Just to refresh the current page.
    }
    
    if(!$_SESSION[username] || !$_SESSION[password]){
    ?>
    <form action="" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="password" /><br />
    <input type="submit" value="Log in" />
    </form>
    <?
    }else{
    echo "Welcome, ".$_SESSION[username].".<br /> You are now logged in.";
    }
    ?>
    
    PHP:
    Just made quickly in the school, not tested at all, but it should work perfect :)
     
    elias_sorensen, Nov 13, 2008 IP
  4. shineDarkly

    shineDarkly Banned

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    how can we help if you havent posted anything, are you debugging or want something already done?
     
    shineDarkly, Nov 13, 2008 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Barti1987, Nov 13, 2008 IP