Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Friday, 30 June 2017

Create Simple Login Form Using PHP Basic

Create Simple Login Form Using PHP Basic


Hello...
How are you.....

The post before, the writter has sharing How to Create Simple Comment Form Using PHP. That posting has been implemented the lesson of input output using PHP MySQL. For the next lesson, the writter will be share how to Create Simple Login Form Using PHP. This lesson is basic of login method in website.

Okay, prepare in this lesson is, Web Server and MySQL, you can use XAMPP on this condition.

Lets go to the Lesson,

First, you could create a Database on MySQL and one table. There are 3 field on the table. Follow this tutorial for simple Lesson.
Now, the writter create a Database with name is blog. Than create table with the name is user. Next, there are 3 fields on the user table, it is a id_user as Primary Key,  username char(32), and password char(32). For detail, look at below.


Thats a structure of Fields on the user table. After you create a Database, Table, And Fields. Now you must fiil the Fields. For expample look at below.


Okay, now we just need a 2 (Two) Pages, 1 (one) for Login Page, dan 1 (one) again for Checking Page.

Lets create a Login Page, this page we will give the name is login.html. Below is the simple script on login page.

<html>
<head>
<title>Login Form</title>
</head>
<body>
<h2>Login Form</h2>
<br>
<form method="POST" action="check.php">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="user" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass" size="20"</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" value="Login">&nbsp;<input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
And than, create the checking page with the name is check.php. Below is the simple script on checking page.

<?php

##### Connection to database #####
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "blog";
$link = mysql_connect($hostname,$username,$password) or die("Error Connection");
mysql_select_db($dbname,$link);
##### End #####

##### Receive Input #####
$user = $_POST[user];
$pass = $_POST[pass];
##### End #####

##### Checking input in table within database #####
$sql = "select * from user where username = $user AND password = $pass";
$hasil = mysql_query($sql) or die("wrong");
$row = mysql_fetch_array($hasil);
if($row == "0") {
echo "<h2>Sorry, username and password does not match</h2>";
}
elseif($row != "0"){
echo "<h2>Login is Successful....</h2>";
}
##### End #####

?>
If all scripts was created. The simple login form was already to use.
The explain of that script is below.

$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "blog";
$link = mysql_connect($hostname,$username,$password) or die("Error Connection");
mysql_select_db($dbname,$link);

its script, are use to create connection between page to database.

$user = $_POST[user];
$pass = $_POST[pass];
its use to receive a input from html page (input username and password). After receive, the value will be include in the variables ($user and $pass).

$sql = "select * from user where username = $user AND password = $pass";
$hasil = mysql_query($sql) or die("wrong");
$row = mysql_fetch_array($hasil);
its use to checking value of $user and $pass on the Database. The basic of this process is on the query syntax. And than the query is executed with mysql_query(); syntax. And than will processed with mysql_fetch_array(); syntax. The result of it will be included on the $row variable. The value of the $row variable is one or zero.


if($row == "0") {
echo "<h2>Sorry, username and password does not match</h2>";
}
elseif($row != "0"){
echo "<h2>Login is Successful....</h2>";
}

Its to use to checking a value of the $row variable, is the value zero or one. If zero means username and password does not match. And if one means username and password does match.



Lets try it.
First. open the login.html page.

Than, fill username and password, than click "Login"
If, success you will look like below


if username and password does not match, you will look at below

Okay, that is Basic of Login Form Using PHP.
On the next time, the writter will share for Advanced Login Form Using PHP.

Happy Paper 4share !!
{ Read More }


Saturday, 20 May 2017

Create eBook How to Create an eBook for Free with Microsoft Word Form

Create eBook How to Create an eBook for Free with Microsoft Word Form


{ Read More }


Sunday, 9 April 2017

Create Simple Form Using PHP

Create Simple Form Using PHP


Now, writter invite you to study hoe to create Simple Fom PHP.
Form example, we will a Comment Form, in the Comment Form, user will insert a name, email, and comment. For easy on this project, we will devide into 3 parts of pages, the pages is  comment_form.html, process.php, view.php, and connection.php.

Before you create that pages, writter suggest to create a Database first. 
Okay, the name of Database who created by writter is blog and the name of table is guest. Tha guest table are having 4 Field, there are id_guest, name, email, and comment. For detail of Fields, look at Below


After you create a Database, Table, and Field. Now, you create a connection.php page. That script like at below
<?
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "blog";

mysql_connect($hostname,$username,$password) or die ("Error connection...");

mysql_select_db($dbname);
?> 
And than, you create a comment_form.html page. That script like at below


<html>
<head>
<title>Comment Form</title>
</head>
<body>
<h1>Comment Form</h1>
<br>
<form method="post" action="process.php">
<table border="0" width="400">
<tr>
<td width="100">Name</td>
<td width="2">:</td>
<td width="298"><input type="text" name="name_guest" size="30"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type="text" name="email_guest" size="30"></td>
</tr>
<tr>
<td>Comment</td>
<td>:</td>
<td><textarea name="comment_guest" cols="24" rows="5"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="send" value="Comment">&nbsp;<input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
<br>
</body>
</html>


Than, you can create a process.php page. That script look at below
<?php
require("connection.php");
$name_guest = $_POST[name_guest];
$email_guest = $_POST[email_guest];
$comment = $_POST[comment_guest];
$sql = "insert into guest(id_guest,name,email,comment) values (,$name_guest,$email_guest,$comment)";
mysql_query($sql) or die ("error SQL query...!!!");
?>
<h3>Your Comment is Successfully....</h3>

And the last page is vew.php. Look at below


<html>
<head>
<title>View Comment</title>
</head>
<body>
<h2>View Comment</h2>
<?php
require("connection.php");
$sql = "select * from guest";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$name = $row[name];
$email = $row[email];
$comment = $row[comment];
echo "Name : <b>$name</b><br>";
echo "Email : <b>$email</b><br>";
echo "Comment : <b>$comment</b><br>";
echo "<hr>";
}
?>
</body>
</html>


Finish, if you want to try it,

First, open the comment_form.html page. And complate the form, look at below


Second, Klik Comment,  if successfully, the this display like at below


Third, view all comment was inserted with open the view.php page. Look at below...

Okay, finish...
if you have any problems, you can leave your ask into comment at below.

Happy Paper 4Share !!!
{ Read More }