PHP Tutorial: Make a Member System // User Login (2/3)




How to create a Member System. Our member system will include user login, registration, email activation, and even a forgot password pages. This video is the …

Original source


35 responses to “PHP Tutorial: Make a Member System // User Login (2/3)”

  1. SOMEONE PLEASE HELP!!!

    I get an error of "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9708073/public_html/index.php on line 30"

    My code so far is:

    <?php
    error_reporting (E_ALL ^ E_NOTICE);
    session_start();
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Login</title>
    </head>
    <body>
    <?php

    $form="<form action="index.php" method="post">
    Username:<br>
    <input type="text" name="user" required="required"><br>
    Password:<br>
    <input type="password" name="pass" required="required"><br>
    <input type="submit" name="sub" value="Login!"><br>
    </form>";

    if($_POST["sub"]){
    $user = $_POST["user"];
    $pass = $_POST["pass"];

    require("connect.php");

    $password = md5(md5("76200".$pass."KbM"));

    $query = mysql_query("SELECT * FROM users WHERE username='$user'");
    $numrows = mysql_num_rows($query);
    if($numrows == 1){

    $row = mysql_fetch_assoc($query);
    $dbuser = $row['username'];
    $dbid = $row['id'];
    $dbpass = $row['password'];
    $dbactv = $row['active'];

    if($password == $dbpass){
    if($dbactv == 1){
    $_SESSION['CurUser'] = $dbuser;
    $_SESSION['CurId'] = $dbid;

    echo "You have logged in as <b>".$_SESSION['CurUser']."</b>";
    }else{
    echo "This account needs to be activated. $form";
    }
    }else{
    echo "Your username or password is incorrect. $form";
    }

    }else{

    }

    mysql_close;

    }else{
    echo $form;
    }

    ?>
    </body>
    </html>

  2. mysqli_query() keeps returning NULL for me.  Even when I flat out tell it what the username is in the query.  I was doing it this way because I am only checking the username and password.  It returns NULL (checked with an if($query==NULL), which worked).

    When checking the username and password with $query, why not just say:

    // check if the entered username is in the database
    if ($user == $query){
      $querpass = mysql_query ("SELECT * FROM users WHERE password = '$password'"

      // check if the entered password is in the database
      if ($password == $querpass){
      }
    }

  3. Hello everyone my member.php displays "Please login to access this page.Login Here" This are my code:  
        <?php
          if ($username && $userid){
    echo "Welcome <b>$username</b>, <a href='./logout.php'>Logout</a>";
    }
    else
    echo "Please login to access this page.<a href='./login.php'>Login Here</a>";
     ?>

    before the Doctype tag 
    <?php
       error_reporting (E_ALL ^ E_NOTICE);
       session_start();
       $userid = $_SESSION['userid'];
       $username = $_SESSION['username'];
       ?> 
    please can anyone help diagnose this code with the original? thanks

  4. Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in N:ftpcompcd10cnProjectlogin1.php on line 51
    The username you entered was not found.

    I AM GEETTING THIS ERROR SOMEONE PLEASE HELP ME ASAP

  5. I have the same problem…

    My login page doesnt seem to check the database for username or password, if i type in a username and password it just says username wasnt found but the details entered are exact same as on database How can i sort out this problem?

  6. I'm working on a server but i a have an error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9040816/public_html/admin/index.php on line 14

    Line 14 is: $numrows = mysql_num_rows($query);
    and the query is line is: $query = mysql_query("SELECT * FROM admins WHERE username='$user'");

    My table is admins!

    Thanks 🙂

  7. For people having problems with the password thing, what I did is I took out the double encryption md5 to make a single encryption, then regenerated my hashed password using a random website to re-generate it, copy pasted it again in my database, and it worked. I think I missed a step when I output my hashed password through the browser. Hope this helps somebody…
    Also, I was told not to use the md5 encryption and use sha256 instead.

  8. Question: Where does the mysql_close(); statement go? I have it after the else of the i($password){ . I'm getting some weird errors and I wanted to make sure they are not being caused by that statement closing the connection to the database too early or too late.

  9. Hey Guys,
    Those who are getting the problem at "Incorrect Password thing", Instead of using
    row['username'] ….Try row['1']..(Or the order in which you have defined Username in you PHPMYADMIN),Because row variable will be an associative array.

Leave a Reply