Use this command in MySql interactive:
mysql>> CREATE DATABASE data
Query OK, 1 row affected (0.00 sec)
mysql>> CREATE TABLE login
>> (id INT NOT NULL AUTO_INCREMENT KEY,
>> username CHAR(20),
>> password CHAR(20));
Query OK, 0 rows affected (0.06 sec)mysql>> INSERT INTO login
>> VALUES
>> (null, 'lady gaga', 'gaga');Query OK, 1 row affected (0.02 sec)
After finishing above, try to create php file:
index.php
<form action="checklogin.php" method="post">Username: <input type="text" name="username"/><br/>
Password: <input type="password" name="password"/><br/>
<input type="submit" value="Log In"/>
</form>
checklogin.php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
mysql_connect("localhost","root","");
mysql_select_db("satu");
$query = "SELECT * FROM login WHERE username='$username'
$username = $_POST['username'];
$password = $_POST['password'];
mysql_connect("localhost","root","");
mysql_select_db("satu");
$query = "SELECT * FROM login WHERE username='$username'
AND password='$password'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
if($count==1){
header("Location: hello.php");
}else{
header("Location: index.php");
}
?>
$result = mysql_query($query);
$count = mysql_num_rows($result);
if($count==1){
header("Location: hello.php");
}else{
header("Location: index.php");
}
?>
hello.php
<?phpecho "<h1>Hello You are in login state<h1>";
?>
No comments:
Post a Comment