Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

PHP Tutorials: Register & Login: User login (Part 2)

Loading...

Sign in or sign up now!
150,124
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Feb 11, 2009

Part of the 'Register & Login' Project from PHP Academy. This tutorials walks you through how to process a username and password based login against details found in a database, set a session, and process a logout function.

Link to this comment:

Share to:

Top Comments

  • This is the full working code for this tutorial. Part I

    <?php

    $username = $_POST['username'];

    $password =$_POST['password'];

    if ($username&&$password)

    { $connect = mysql_connect("localhost","roo­t","") or die ("cannot connect to the database"); mysql_select_db("phpalex") or die("Couldn't find db"); $query = mysql_query("SELECT * FROM user1 WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) {

  • rihanna's ass keeps distracting me!!

see all

All Comments (501)

Sign In or Sign Up now to post a comment!
  • @helldrake77777 google for xamp if ur on windows and mamp if ur on mac. its a package that gives you a local server plus mysql database and phpmyadmin, free :)

  • @doreto95

    Try this,

    put an $squery = mysql_query($query); // after de $query thing and after that modify while ($row = mysql_fetch_assoc($query))

    with while ($row = mysql_fetch_assoc($squery))

  • mysql*

  • do i have to pay something 4 this locallhost and msql?

  • This way has a MASSIVE security risk of SQL injections. Imagine this input for username/password:

    '; DROP TABLE users; --

    This would fail to log them in BUT delete all users in the table users.

    You should add this before running it through the database:

    $username = mysql_real_escape_string($user­name);

    $password = mysql_real_escape_string($pass­word);

    I know, it's not basic, but one should know dangers of SQL injections. It would also be good to md5 or sha1 all passwords. *complicates everything*

  • why at 5:23 i get this error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\XAMPP\htdocs\website\login.­php on line 13

    That user doesn't exist!

  • i was getting wrong password error, so i started over, and for some reason it work.............started over back from tutorial part 1 and it works,

  • The 1 is not appearing on my screen nothing happened like before

  • @fruitman89 hahahaha i agree

View all Comments »
Loading...

0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more