|
 |
|
สอบถามหน่อยค่ะ เพิ่ม/แก้ไข/ลบหน้าสมาชิก พอแก้เสร็จจะรีเฟรชให้ไปล๊อคอินใหม่ |
|
 |
|
|
 |
 |
|
มือใหม่หัดเขียนค่ะ ช่วยรบกวนชี้แนะหน่อยนะค่ะ
1. โคด add ข้อมูล และ edit ตรงส่วนนี้ พอมัน add สมาชิกใหม่ เหรอ edit สมาชิกใหม่เสร็จเรียบร้อย เข้า databaser มันจะรีเฟรชกลับไป Login ใหม่ตลอดเวลาที่เพิ่มค่า หรือแก้ไขค่า ช่วยดูให้หน่อยนะค่ะ
2. พอคลิ๊กลบสมาชิก โคดไม่ลบค่าฟิลล์ user ที่จะลบให้ค่ะ งง ว่าผิดตรงใหนค่ะ
งง มากเรยค่ะ นั่งหามา 2 ชมแล้ว หาไม่เจอ รบกวนช่วยดูให้หน่อยนะค่ะ T_______T ขอคำชี้แนะหน่อยนะค่ะ
Member.php (หน้าแสดงข้อมูลทั้งหมด)(PHP)
<?php
//================= ลบข้อมูล ===========================//
if($action == "delete") {
$del = mysql_query("DELETE FROM tb_member WHERE user_id = $user_id");
if(!del) {
echo mysql_error();
}
else {
echo"<script language='JavaScript'>";
echo"alert('ข้อมูลถูกลบแล้ว');";
echo"window.location='admin_page.php?url=member.php';";
echo"</script>";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="../css/style.css" />
</head>
<body>
<?php
$sql = "SELECT * FROM tb_member ";
$rs = mysql_query($sql);
?>
<div style="width:700px;" align="right" class="BodyStyle"><a href="admin_page.php?url=member_edit.php">เพิ่มข้อมูลสมาชิก</a></div>
<table width="700" border="1" class="BodyStyle">
<thead>
<tr>
<td width="41">ลำดับ</td>
<td width="117">Username</td>
<td width="98">Password</td>
<td width="119">ชื่อ-นามสกุล</td>
<td width="40">เพศ</td>
<td width="62">วันเกิด</td>
<td width="79">ระดับชั้น</td>
<td width="107">Email</td>
<td width="41">Status</td>
<td width="39">แก้ไข</td>
<td width="29">ลบ</td>
</tr>
</thead>
<tbody>
<?php if(!empty($rs)): ?>
<?php while ($r = mysql_fetch_assoc($rs)): ?>
<tr align="center">
<td><?php echo ++$n; ?></td>
<td><?php echo $r["username"];?></td>
<td><?php echo $r["password"];?></td>
<td><?php echo $r["name"];?></td>
<td><?php echo $r["sex"];?></td>
<td><?php echo $r["birthdate"];?></td>
<td><?php echo $r["class"];?></td>
<td><?php echo $r["email"];?></td>
<td><?php echo $r["status"];?></td>
<td><a href="admin_page.php?url=member_edit.php&user_id=<?php echo $r["user_id"];?>">แก้ไข</a></td>
<td><a href="member.php?user_id=<?php echo $r["user_id"]; ?>&action=delete" onClick="return confirm ('ยืนยันการลบ')">ลบ</a></td>
</tr>
<?php endwhile ?>
<?php endif ?>
</tbody>
</table>
<?php include_once "../mysql_close.php"; ?>
</body>
</html>
member_edit.php (หน้า แก้ไข และเพิ่มค่าใหม่) (PHP)
<?php
//--------------- เช็คค่าว่าง------------------//
if (!empty($_GET["user_id"])) {
$rs = mysql_query("SELECT * FROM tb_member WHERE user_id = $_GET[user_id]");
$r = mysql_fetch_assoc($rs);
}
//================================//
?>
<form method="post" action="admin_page.php?url=member_save.php" >
<div style="width:400px;" class="HeaderText">
<div style="float:left; width:150px; ">
<div class="login_regitser">Username</div>
<div class="login_regitser">Password</div>
<div class="login_regitser">ชื่อ-นามสกุล</div>
<div class="login_regitser">เพศ</div>
<div class="login_regitser">วันเกิด</div>
<div class="login_regitser">ระดับชั้น</div>
<div class="login_regitser">Email</div>
<div class="login_regitser">Status</div>
</div>
<div style="float:right; width:250px;">
<div class="login_regitser"><input type="text" name="username" value="<?php echo $r["username"]; ?>" /></div>
<div class="login_regitser"><input type="text" name="password" value="<?php echo $r["password"]; ?>"></div>
<div class="login_regitser"><input type="text" name="name" value="<?php echo $r["name"]; ?>"></div>
<div class="login_regitser">
<input type="radio" name="sex" value="man" <? if($r["sex"]=="man"){?>checked<?}?>>ชาย
<input type="radio" name="sex" value="woman" <? if($r["sex"]=="woman"){?>checked<?}?>>หญิง
</div>
<div class="login_regitser"><input type="text" name="birthdate" value="<?php echo $r["birthdate"]; ?>"></div>
<div class="login_regitser"><input type="text" name="class" value="<?php echo $r["class"]; ?>"></div>
<div class="login_regitser"><input type="text" name="email" value="<?php echo $r["email"]; ?>"></div>
<div class="login_regitser">
<select name="status" id="status">
<option value="user" <? if($r["status"]=="user"){?>selected<?}?>>user</option>
<option value="admin" <? if($r["status"]=="admin"){?>selected<?}?>>admin</option>
</select>
</div>
</div>
<div><input type="submit" value="บันทึก"/></div>
</div>
<input type="hidden" name="user_id" value="<?php echo $r["user_id"]; ?>" />
</form>
member_save.php (หน้าเซฟสมาชิก)
<?php
include_once "../connect.php";
$user_id = $_POST["user_id"];
$username = $_POST["username"];
$password = $_POST["password"];
$name = $_POST["name"];
$sex = $_POST["sex"];
$birthdate = $_POST["birthdate"];
$class = $_POST["class"];
$email = $_POST["email"];
$status = $_POST["status"];
if (empty($user_id)) {
$sql = "INSERT INTO tb_member (
username,
password,
name,
sex,
birthdate,
class,
email,
status
) VALUES (
'$username',
'$password',
'$name' ,
'$sex',
'$birthdate',
'$class',
'$email',
'$status'
)";
} else {
//update
$sql = " UPDATE tb_member SET
username = '$username',
password = '$password',
name = '$name',
sex = '$sex',
birthdate = '$birthdate',
class = '$class',
email = '$email',
status = '$status'
WHERE user_id = $user_id
";
}
if (mysql_query($sql)) {
header("location:admin_page.php?url=member.php");
} else {
echo mysql_error();
}
include_once "../mysql_close.php";
?>
admin_page.php (หน้า index ของระบบแอดมิน)
<?
ob_start();
session_start();
if($_SESSION['user_id'] == "")
{
header("refresh: 1; url=../index.php" );
echo "Please Login!";
exit();
}
if($_SESSION['status'] != "admin")
{
header("refresh: 1; url=../index.php" );
echo "This page for Admin only!";
exit();
}
include_once "../connect.php";
$strSQL = "SELECT * FROM tb_member WHERE user_id = '".$_SESSION['user_id']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="../css/style.css" />
</head>
<body>
<div class="center">
<div class="menu_left BodyStyle">
<?php include "login_finish.php" ?>
<?php include "../admin/menu_left.php"?>
</div>
<div class="content_right BodyStyle">
<?php
if(!empty($_GET["url"]))
{
include_once $_GET["url"];
} else {
echo "ระบบจัดการข้อมููลเว็บไซต์";
}
?>
</div>
</div>
</body>
</html>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2013-07-11 17:24:12 |
By :
angeleye |
View :
721 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูพวกตัวแปร Session กับตัวแปรที่สร้างใหม่ครับ เข้าใจว่ามันน่าจะชนกันน่ะครับ 
|
 |
 |
 |
 |
Date :
2013-07-12 10:58:33 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะคุณ TC Admin เดี๋ยวจะลองไล่ดูค่า session ค่ะ ^^
|
 |
 |
 |
 |
Date :
2013-07-12 21:43:53 |
By :
angeleye |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ ridirect ไปยังหน้า logout ให้ unregissession ตามปกติไม่ได้เหรอครับ 
|
 |
 |
 |
 |
Date :
2013-07-12 21:55:56 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|