|
 |
|
เรื่องระบบ session ไม่ยอมคงสถานะ admin รบกวนด้วยครับผม |
|
 |
|
|
 |
 |
|
ไฟล์แรก
Code (PHP)
<?
session_start();
if($_SESSION['UserID'] == "")
{
echo "</br></br><center><b>กรุณาล็อคอิน !</b></center>";
echo "<center><b></br>กลับสู่<a href='login.php'> หน้าล็อคอิน</a></b></center>";
exit();
}
if($_SESSION['Status'] != "ADMIN")
{
echo "</br></br><center><b>เฉพาะผู้ดูแลระบบเท่านั้น !</b></center>";
echo "</br><center><b>กลับสู่<a href='login.php'> หน้าล็อคอิน</a></b></center>";
exit();
}
?>
<html>
<head>
<title>ระบบคลังสินค้าร้านธนพร</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body bgcolor="#cc9520">
<br><br>
<form method="POST" action="add_member02.php">
<table align="center" border="1" bordercolor="black">
<center><h2>ระบบเพิ่มผู้ใช้งาน</h2></center></br>
<tr>
<td><b>รหัส</td>
<td><input type="text" name="UserID"></td>
</tr>
<tr>
<td><b>ชื่อผู้ใช้</td>
<td><input type="text" name="Username"></td>
</tr>
<tr>
<td><b>รหัสผ่าน</td>
<td><input type="password" name="Password"></td>
</tr>
<tr>
<td><b>ยืนยันรหัสผ่าน</td>
<td><input type="password" name="ConPassword"></td>
</tr>
<tr>
<td><b>ชื่อ - สกุล</td>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td><b>อีเมล์</td>
<td><input type="text" name="Email"></td>
</tr>
<tr>
<td><b>เบอร์โทร</td>
<td><input type="text" name="Tel"></td>
</tr>
<tr>
<td><b>ที่อยู่</td>
<td><input type="text" name="Address"></td>
</tr>
<tr>
<td><b>Status</td>
<td><select name="Statuslist">
<option value="01">Admin
<option value="02">User</td>
</tr>
<tr>
<td><b>รูปภาพ</td>
<td><input type="file" name="Member_Pic"></td>
</tr>
</table></br>
<center><input type="submit" name="add_member" value=" เพิ่มข้อมูล ">
</form>
<form method="post" action="edit_member01.php">
<center><input type="submit" name="return" value="กลับสู่หน้าจัดการผู้ใช้">
</body>
</html>
ไฟล์ที่สอง
Code (PHP)
<?
session_start();
if($_SESSION['UserID'] == "")
{
echo "</br></br><center><b>กรุณาล็อคอิน !</b></center>";
echo "<center><b></br>กลับสู่<a href='login.php'>หน้าล็อคอิน</a></b></center>";
exit();
}
if($_SESSION['Status'] != "ADMIN")
{
echo "</br></br><center><b>เฉพาะผู้ดูแลระบบเท่านั้น !</b></center>";
echo "</br><center><b>กลับสู่<a href='login.php'>หน้าล็อคอิน</a></b></center>";
exit();
}
?>
<html>
<head>
<title>ระบบคลังสินค้าร้านธนพร</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body bgcolor="#cc9520">
</br></br><center><h2>ระบบเพิ่มผู้ใช้งาน</h2></center>
<?php
include("config.php");
$UserID=$_POST["UserID"];
$Username=$_POST["Username"];
$Password=$_POST["Password"];
$ConPassword=$_POST["ConPassword"];
$Name=$_POST["Name"];
$Email=$_POST["Email"];
$Tel=$_POST["Tel"];
$Address=$_POST["Address"];
$Status=$_POST["Statuslist"];
if(trim($_POST["Username"]) == "")
{
echo "<center><font color='red'>กรุณาระบุ Username !</font></center>";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if(trim($_POST["Password"]) == "")
{
echo "<center>"."<font color='red'>"."Error : "."กรุณาระบุ Password !";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if(trim($_POST["ConPassword"]) == "")
{
echo "<center>"."<font color='red'>"."Error : "."กรุณาระบุ Confirm Password !";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if($_POST["Password"] != $_POST["ConPassword"])
{
echo "<center>Password ไม่ตรงกัน !</center>";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if(trim($_POST["Name"]) == "")
{
echo "<center>"."<font color='red'>"."Error : "."กรุณาระบุ Name !";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if(trim($_POST["Email"]) == "")
{
echo "<center>"."<font color='red'>"."Error : "."กรุณาระบุ Email !";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if(trim($_POST["Tel"]) == "")
{
echo "<center>"."<font color='red'>"."Error : "."กรุณาระบุ Tel !";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
if(trim($_POST["Address"]) == "")
{
echo "<center>"."<font color='red'>"."Error : "."กรุณาระบุ Address !";
echo "<center>กลับไปสู่<a href='add_member01.php'>เพิ่มผู้ใช้งาน</a></center>";
exit();
}
mysql_query("SET NAMES UTF8");
$sql = " INSERT INTO member (UserID,Username,Password,Name,Email,Tel,Address,Status) value ('$UserID','$Username','$Password','$Name',
'$Email','$Tel','$Address','$Status') ";
$result=mysql_query($sql);
if($result){
echo "<center><b><font color='blue'>เพิ่มผู้ใช้งานสำเร็จ !</font></b></center>";
}else{
echo "<center><b><font color='red'>เพิ่มผู้ใช้งานล้มเหลว !</font></b></center>";
}
?>
<form method="post" action="edit_member01.php">
</br><center><input type="submit" name="return" value="กลับไปเมนูจัดการผู้ใช้งาน"></center></form>
</body>
</html>
คือพอแอดแล้ว กดรีเทิร์นกลับมา มันจะ ERROR ให้ล็อคอินใหม่อ่ะครับ รบกวนช่วยดูให้ทีนะครับผม
ขอบคุณมากครับ T__T
Tag : PHP, MySQL, HTML/CSS

|
|
 |
 |
 |
 |
Date :
2012-04-23 14:08:41 |
By :
Sompoiiz |
View :
1111 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าไม่สั่ง session_destroy(); มันก็ไม่หายหรอกครับ
|
 |
 |
 |
 |
Date :
2012-04-23 14:18:47 |
By :
rootElement@kmutnb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่แน่ใจ รองเอาsession_start();ไปไว้บันทรรดแรก บันทรรดที่1เลยน่ะ เกรงว่าอนาคตคุณจะเจอ ERROE Header
ยังไงลองเอาหน้า authen มาดูคับ เผื่อประกาศเซสชั่นผิด
|
ประวัติการแก้ไข 2012-04-23 15:05:42
 |
 |
 |
 |
Date :
2012-04-23 14:59:11 |
By :
gmgo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอาแบบง่ายๆเลยนะ
ลอง echo session ดูเลย
|
 |
 |
 |
 |
Date :
2012-04-24 18:03:06 |
By :
asustak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณไปใช้ตัวแปร status ซ้ำกันครับ เปลี่ยนซะ
Code (PHP)
$Status=$_POST["Statuslist"];
|
 |
 |
 |
 |
Date :
2012-04-24 20:25:14 |
By :
000su000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|