Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Help with PHP Login

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #41858

    Hello css-tricks community.

    I am trying to work on a little area for a website where the administrator can login and update a php table that offers 3 services. I have the php table working and updating properly. However when I did the login page. My page will not redirect to the page that I select. I used the [phpeasy steps login tutorial] but I cannot figure out why it is not working. I can get get it to tell me if the user name and password is wrong and also I can successfully sign out. Is there another tutorial I could use, or could you suggest what is wrong with my code. I studying php and I am trying to learn what is wrong with it. Any help will be greatly appreciated!!!** Thank you in advance!**
    This is for the login page
    [codepen for login page…](http://codepen.io/cristinalmanza/full/JzmLc “Code Pen for login”)

    This is for the login action php:



    // Connect to server and select databse.
    mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);
    mysql_select_db(“$db_name”)or die(“cannot select DB”);

    // Define $myusername and $mypassword
    $myusername=$_POST;
    $mypassword=$_POST;

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql=”SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword'”;
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);

    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){

    // Register $myusername, $mypassword and redirect to file “login_success.php”
    session_register(‘myusername’);
    session_register(‘mypassword’);
    header(‘Location: http://www.mywebsite.com/php/success_login.php’);
    }
    else {
    echo “Wrong Username or Password”;
    }
    ob_end_flush();
    ?>

    (http://www.phpeasystep.com/phptu/6.htmlhttp://www.phpeasystep.com/phptu/6.html”)

    #120345
    hotpink
    Member

    Something I noticed in your example code…

    This comment has “login_success.php”

    // Register $myusername, $mypassword and redirect to file “login_success.php”

    But this line has “success_login.php”

    header(‘Location: http://www.mywebsite.com/php/success_login.php’)

    Could this be the issue?

    #120346

    Thank you so much for your response hotpink! I will do that and look at it and see if it is the problem. Thank you for taking time to check the code for me =) I really appreciate it

    #120347

    I just checked and that is not it =(.

    #120364
    Bonzai
    Participant

    I wouldn’t recommend using mysql_connect for your login. You would be much better off using PDO. Here’s a tutorial on how to use it:

    [PDO tutorial](http://www.phpeveryday.com/articles/PHP-Data-Object/PDO-Tutorial-P842.html “PDO tutorial”)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.