web ne
<?php
//session_start();
if(isset($_POST['ok']))
{
if($_POST['username'] == NULL)
echo "vui long nhap username<br/>";
else
$u=$_POST['username'];
if($_POST['password'] == NULL)
echo "vui long nhap password<br/>";
else
$p=$_POST['password'];
if($u && $p)
{
$conn=mysql_connect("localhost","root","") or die("can't connect this database");
mysql_select_db("BookEShop",$conn);
$sql="select * from user where username='".$u."' and pass='".$p."'";
//echo $sql;
$query=mysql_query($sql) or die ('Lenh sql khong thuc hien duoc');
if(mysql_num_rows($query) == 0)
echo " Sai Username hoac password,xin vui long thu lai";
else
{
$row=mysql_fetch_array($query);
session_register("userid");
session_register("level");
$_SESSION['userid'] = $row[Username];
$_SESSION['level'] = $row[level];
//echo $_SESSION['userid'];
if ($_SESSION['userid'] && $_SESSION['level']==0)
header('Location: admin.php');
else
header('Location: loginnew1.php');
}
}
}
?>
<form action="loginnew1.php" method = post>
Username: <input type='text' name='username' value='' size=20></br>
Password: <input type='password' name='password' size=20>
</br>
<input type='submit' value='Dang Nhap' name='ok'>
<input type='reset' value='reset' name='reset'>
</form>
Them
<?
session_start();
//echo 'xin chao ban '.$_SESSION['userid'];
//echo "$_SESSION['username']";
//echo "$_SESSION['level']";
if(isset($_SESSION['userid']) && $_SESSION['level'] == 0)
{
if (isset($_POST['cmd']))
add();
else
input();
}
else
{
header('location:login.php');
exit();
}
?>
<?
function input()
{
?>
<form action=add_user.php method=post>
Username: <input type=text name=user size=25 />
Password: <input type=password name=pass size=25 />
rePassword: <input type=password name=repass size=25 />
Email: <input type=text name=email size=25 />
Level: <select name=level>
<option value=0>admin</option>
<option value=2>user</option>
</select>
<input type=submit name=cmd value="Dang ki" />
<input type="reset" name="rs"/>
</form>
<? } ?>
<?
function add()
{
if ($_POST['user']==NULL || $_POST['pass']==NULL)
{
echo'ban chua nhap user hoac pass.moi ban nhap lai';
input();
}
else
{
if($_POST['pass'] != $_POST['repass'])
{
echo 'pass khong giong nhau';
input();
}
else
{
$u=$_POST['user'];
$e=$_POST['email'];
$l=$_POST['level'];
$p=md5($_POST['pass']);
}
if ($u && $p)
{
$link=mysql_connect("localhost","root","") or die("can't connect this database");
mysql_select_db("BookEShop",$link);
$sql="select * from user where username='".$u."'";
$result=mysql_query($sql);
if( mysql_num_rows($result) != 0)
{
echo 'user da ton tai';
input();
}
else
{
//$insert= "INSERT INTO 'user' ( 'Username' , 'Pass' , 'Email' , 'Level' )VALUES ('".$u."','".$p."','".$e."','".$l."')";
$insert="insert into User values('".$u."','".$p."','".$e."','".$l."')";
mysql_query($insert) or die ('ko thuc hien duoc insert');
//$query2=mysql_query($sql2);
echo'insert thanh cong';
}
}
}
}
?>
Admin
<?php
session_start();
//echo 'xin chao ban '.$_POST["username"];
//echo 'xin chao ban '. $_SESSION['userid'];
//echo 'xin chao ban '. $_SESSION['level'];
if (isset($_SESSION['userid']) && $_SESSION['level'] == 0)
// t?i dây th?c thi các ho?t d?ng khi dang nh?p thành công.
echo 'xin chao ban '.$_SESSION['userid'];
/*else
{
header("location: login.php");
exit();
}
*/
?>
Hien thi
<?php
//session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","") or die ("khong the ket noi CSDL");
mysql_select_db("BookEShop",$conn);
$sql="select * from user";
$result = mysql_query($sql) or die ("khong thuc hien duoc cau lenh SQL");
if (mysql_num_rows($result) != 0)
{
echo '<table border="1" cellpadding="5" cellspacing="0">';
echo '<caption> B?ng User</caption>';
echo '<tr>';
echo '<td> STT</td>';
echo '<td> Username </td>';
echo '<td> Pass </td>';
echo '<td> Email </td>';
echo '<td> Level </td>';
echo '</tr>';
$count=1;
while ($rows=mysql_fetch_array($result))
{
echo '<tr>';
echo '<td>'.$count++.'</td>';
echo '<td>'.$rows[0].'</td>';
echo '<td>'.$rows[1].'</td>';
echo '<td>'.$rows[2].'</td>';
echo '<td>'.$rows[3].'</td>';
echo '</tr>';
}
echo '</table>';
}
?>
</body>
</html>
Bạn đang đọc truyện trên: AzTruyen.Top