How to Create Login Form in PHP using Dreamweaver and MySQL Database?[With Source Code]
Hello guyz, In this simple but very important article i am going to give some tips to you how to create a login form in PHP using Dreamweaver CC and MySQL Database. Creating a login form is very simple tasks but it tells you how to connect to the database, even how to create database in you localhost and how to create table in the database and many more things.
Before this you should know how to define site and testing server in Dreamweaver cc because PHP is Server site scripting language thats why it does not executed by the browser. So for this reason you have to install the server application like Wamp server, xamp server for windows and PAMP Server for mac. Before starting this little project first read this article:
Now follow the following steps:
[sociallocker]1. After download and installing open it and then open your localhost, for this open up your any browsing software and type localhost or 127.0.0.1 in the address bar. Then new page will appear then scroll down and find phpmyadmin and click on that. Then you will be able to see the login page. Login in by entering username and password (Default username is root and password is empty). And then click on new and create one database having any name you want and the click ok, then create table having any number of field you want but i am using four field in this case and click on go. After that, you need to insert the field name like: username, password. and then select the length as well as data type as your requirement and then click on save. You can watch the video for this designing part, you may understand better in video.
2. Write the following code:
<!doctype html> <?php $servername = "localhost"; $username="root"; $password=""; $dbname="test"; //create connection $conn=new MySQLi($servername,$username,$password,$dbname); //check the connection if($conn->connect_error){ die("connection failed".$conn->connect_error); } if(isset($_POST['user'])){ $user=$_POST['user']; $pass =$_POST['pass']; $sql ="select * from login where username = '".$user."' and password='".$pass."' LIMIT 1"; $result = $conn->query($sql); if($result->num_rows>0){ echo("you have successfully loggined"); exit(); }else{ echo("goto previous page"); exit(); } } ?> <html> <head> <meta charset="utf-8"> <title>login form</title> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%20type%3D%22text%2Fcss%22%3E%0Abody%20%7B%0Abackground-color%3A%20%23F1E2E2%3B%0A%7D%0A%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<style>" title="<style>" /> </head> <body> <form method="post" action="login.php"> username:<input type="text" name="user"><br><br> password:<input type="text" name="pass"><br><br> <input type="submit" value="login"> </form> </body> </html>
3. save the file in localhost and run.
[/sociallocker]
For more details: