PHP Programming Tutorial – Creating A Simple MySQL Login Form

Follow me on Twitter @ http://twitter.com/tktutorials
Check out my website @ http://www.timkipptutorials.com

In this tutorial we will be building a very simple login form using PHP and MySQL. Please note that this is very basic and I am not applying and security features to this tutorial. I will be covering a more advanced login system in future tutorials.

Source code is located on my website under the “Code Bank” section.

Comments

Reinis Barzdins says:

Very Easy,Very Fast,Very Effective,…..Like,Subcribe !

Kistlak Rajapaksha says:

Thank You Very Much !! 😀

Symi Khan says:

please help me to correct this error
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in E:xampphtdocsproject 1login.php on line 16
inValid information…

Aman Bhargava says:

I had to practically scour the universe to find this gem. I learned a bunch of pointless stuff on the way, thanks so much for this tutorial.

Sa Van says:

very good teacher can make video php login to admin

Dhruv Rawat says:

Really great tutorial ,clear cut and to the point . Great Job !

Smasher says:

It would just reload the page each time i press Submit, any help?

Ruaridh Wylie says:

Excellent Tut man! I was stuck with the connection to my DB but this has cleared it up! Keep the vids coming 😀

Ahmed Khaled says:

name of the text editor ?

kO qUillion says:

Great! I’ve been pulling my hair out trying to find the most basic connection possible with least amount of files etc. almost had to go to second page! :)

Andy Varela says:

really useful and clear! you saved my ass, cheers mate!!!

Speaker Cringe says:

Somebody help me? Wouldn’t let me post my code here so I made a link: http://www.tomshardware.com/answers/id-2830409/connect-html-php-mysql-server.html#16793872

Catalin Chira says:

Hi,could you please let me know what is wrong here . When checking it results with this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rvreau50/public_html/login.php on line 14

Line 14 is this one: if (mysql_num_rows($res) == 1) {

Thank you !

sourajit saha says:

couldn’t have been any better tutorial for a beginner :) thanks a ton , got the perfect video after so many wasted videos .

Rae Loyola says:

cant run?
why?
help pls! thanks you. :(
< ?php $host = "localhost"; $user ="root"; $pass = ""; $db = "login"; mysql_connect($host, $user, $pass); mysql_select_db($db); if (isset($_POST['username'])) { $username = $_POST['username']; $password = $_POST['password']; $sql = "SELECT * FROM users WHERE username='".$username."' AND passsword='".$password."' LIMIT 1"; $res = mysql_query($sql); if (mysql_num_rows($res) == 1) { echo "you have successfully logged in."; exit(); } else { echo "Invalid login Information. please returnto the previous page."; exit(); } } ?>

3BingBongHand says:

PHP & MySQL with MVC Frameworks – Self-Paced
https://twitter.com/WikiOffer/status/820088361062801408

David Ashby says:

Nice tutorial, thanks.

Vinothkumar P says:

nice video understandable………………………………

Ngonnly Hun says:

eh bro what does isset mean?

Coco Martin says:

at last! good video tutorial about this topic. thank you very much sir!

Phuong Le says:

thanks you so much, love you

Sanjeet shrestha says:

Great job thanx for ur assist

Lasitha G Gunasinghe says:

If password and username are correct how i can go to next page

Tony Saint Hua says:

Hi Tim, Love your tutorial, but your official website is NOT user friendly. I can NOT find the “CODE BANK” section anywhere ?

Jim John says:

Is this way secure tho?

khmer happy says:

Hello Sir! I want to create an account for one person by using php. Could you do and post it? Thanks a lot!

cRcPS says:

Hello! It’s definitely a great tutorial! But I encountered a problem , can anyone help me?

The code I wrote seems to be perfectly fine, but for some reason it wouldn’t connect to db. The issue is that even if I use correct username and password it gives me “Invalid login information. Please return to the previous page.”

In the values of $host, $user, $pass and $db I’m 100% sure. Thanks in advance :)

< ?php $host = "localhost"; $user = "root"; $pass = ""; $db = "the allmighty one"; mysql_connect($host, $user, $pass); mysql_select_db($db); if (isset($_POST['username'])) { $username = $_POST['username']; $passwrod = $_POST['password']; $sql = "SELECT * FROM users WHERE username='".$username."' AND password='". $password."' LIMIT 1"; $res = mysql_query($sql); if (mysql_num_rows($res) == 1) { echo "You ahve successfully logged in."; exit(); } else { echo "Invalid login information. Please return to the previous page."; exit(); } } ?>

Username:

Password:


Ivo Carbajo says:

[11-Oct-2015 04:08:41 Europe/Moscow] PHP Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/abumfluc/public_html/login/login.php on line 15

Wha? how do i fix that? what did i do wrong?

Việt Hoàng says:

could you tell me how to do this with PDO please, I get stuck in this :(

Edward Leung says:

Do you know how I can fix this error.. “The requested URL /Assignment 1/login.php was not found on this server.” When I typed in the username and password on the login form. Thanks in advance

Ismitha Development says:

Great tutorial but, it’s vulnerable tu a sqli?

Shahid Hiraj says:

Thank you for very informative video…

Symi Khan says:

thank you so much..
ALLAH bless you !..

Shashi Kiran says:

registration form video?

TheAngryGinger says:

really helpful

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours