|
|
|
รบกวนขอคำแนะนำและขอความช่วยเหลือหน่อยคะคะถ้าผู้ใช้งาน login อยู่ห้ามลบต้องทำยังไงคะ |
|
|
|
|
|
|
|
test1.php
Code (PHP)
<meta charset="utf-8">
<?php
@session_start();
if( !isset($_SESSION["Username"]) or $_SESSION["Username"] == NULL )
{
$message = "กรุณาเข้าสู่ระบบ";
echo "<script type='text/javascript'>alert('$message');</script>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=login.php\">";
exit();
}
include("connect.php");
include("slide.php");
mysql_query("SET NAMES UTF8");
// เช็คค้นหา
if(isset($_GET["item"])){
$select_dep=$_GET["item"];
}else{
$select_dep="";
}
if(isset($_GET["isos"])){
$select_iso=$_GET["isos"];
}else{
$select_iso="";
}
if(isset($_GET["type_iso"])){
$select_type=$_GET["type_iso"];
}else{
$select_type="";
}
mysql_connect("localhost","root","");
mysql_select_db("mydatabase");
//*** Update Last Stay in Login System เช็คเวลาในการlogin
$sql = "UPDATE member SET LastUpdate = NOW() WHERE UserID = '".$_SESSION["UserID"]."' ";
$query = mysql_query($sql);
$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Creative - Bootstrap 3 Responsive Admin Template">
<meta name="author" content="GeeksLabs">
<meta name="keyword" content="Creative, Dashboard, Admin, Template, Theme, Bootstrap, Responsive, Retina, Minimal">
<link rel="shortcut icon" href="img/favicon.png">
<title>COTTO</title>
</head>
<body>
<!-- container section start -->
<section id="container" class="">
<!--main content start-->
<section id="main-content">
<section class="wrapper">
<div class="row">
<h3> <img src="img/7885963_orig.png" width="60px" height="50px"> รายการเอกสาร</h3>
<div class="cols-lg-9 cols-md-12">
<hr>
<div class="panel panel-default">
<div class="panel-body">
<h4>ตารางข้อมูล</h4>
<table border="0">
<tr>
<td width="5%"><input type="button" class="btn btn-success" onclick="window.location.href='createaccount.php'" value="เพิ่มข้อมูล"/></td>
<td width="5%"><input type="button" class="btn btn-default" onclick="window.location.href='./test1.php'" value="Refresh Data"/></td>
</tr>
</table>
<?php
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
?>
<table class="table bootstrap-datatable countries">
<thead>
<?php
$strSQL = "SELECT * FROM member";
$strSQL=$strSQL." order by UserID ";
$db = "mydatabase";
mysql_query("SET NAMES UTF8");
$tmp = mysql_query($strSQL) or die (mysql_error());
$result = mysql_select_db($db);
if(!$result){
die('Could not find database called supplier: '. mysql_error());
}
?>
<tr>
<th align="center">#</th>
<th>หน่วยงาน</th>
<th>ไฟล์เอกสาร</th>
<th>Revise</th>
<th>รายละเอียด</th>
<th>มาตรฐาน</th>
<th>ชื่อแฟ้ม</th>
<th></th>
</tr>
</thead>
<?php
$i=1;
while($rows = mysql_fetch_array( $tmp ))
{
echo "<tr>";
echo '<td align="center"><font color="#000000">' . $i++. '</font></td>';
echo '<td align="center"><font color="#000000">' . $rows['Name'] . '</font></td>';
echo '<td align="center"><font color="#000000">'. $rows['Username'] . '</font></td>';
echo '<td align="center"><font color="#000000">' . $rows['Status'] . '</font></td>';
?>
<input type="hidden" value="<?=$rows['UserID']?>">
<?php
echo '<td align=center><a href=delete_member.php?id='.$rows["UserID"].' onclick="return confirm(\'คุณต้องการลบข้อมูลหรือไม่?\');" class="btn btn-danger btn-xs"> ลบ </a></td>';//<img src="img/icons/delete.png" width="20px" height="20px">
echo "</tr>";
}
$i++;
?>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div class="row">
<div class="widget-foot"> </div>
</div>
</div>
</div>
<div class="col-lg-8"></div>
<div class="widget-foot">
<!-- Footer goes here -->
</div>
</div>
</div>
</div>
</div>
<!-- project team & activity end -->
</section>
</section>
<!--main content end-->
</section>
<!-- container section start -->
</body>
</html>
delete_member.php
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
include ("connect.php");
if (isset($_GET['id']))
{
$id = $_GET['id'];
$select = "SELECT LastUpdate FROM member WHERE UserID = '$id'";
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$result = mysql_query($select)or die(mysql_error());
$count = mysql_num_rows($result);
if($count > 0) {
$message = "ข้อมูลถูกใช้งานอยู่ไม่สามารถลบได้ในขณะนี้";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else {
$message = "ลบข้อมูลเสร็จสิ้น";
echo "<script type='text/javascript'>alert('$message');</script>";
$result = mysql_query("DELETE FROM `member` WHERE UserID= '".$id."'")
or die(mysql_error());
}
echo '<script>location = "test1.php"</script>';
}
else
{
echo "<meta http-equiv='refresh' content='0; url=test1.php'>";
// echo '<script>location = "department.php"</script>';
}
mysql_close($conn);
?>
คือ จากรูปนะคะ มีคนที่เป็น admin login ใช้งานอยู่จะต้องทำยังไงให้คนที่ไม่ได้ใช้งานลบไม่ได้และจะลบคนที่ไม่ได้ใช้งาน จากในโค้ด delete_member.php ไม่ว่าจะ login ไม่ login มันไมสามารถได้ทั้งหมดเลยและ ตาราง member ไม่ได้มีผูกกับตารางอื่นๆ ขอคำแนะนำหน่อยคะ รบกวนด้วยคะ
Tag : PHP
|
ประวัติการแก้ไข 2016-07-25 10:13:02 2016-07-25 10:25:31
|
|
|
|
|
Date :
2016-07-25 10:11:21 |
By :
POMP |
View :
1519 |
Reply :
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
session_start();
include ("connect.php");
if($_SESSION["Username"] != ""){ // start
if (isset($_GET['id']))
{
$id = $_GET['id'];
$select = "SELECT LastUpdate FROM member WHERE UserID = '$id'";
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$result = mysql_query($select)or die(mysql_error());
$count = mysql_num_rows($result);
if($count > 0) {
if ($result['LastUpdate']=="") {
$message = "ข้อมูลถูกใช้งานอยู่ไม่สามารถลบได้ในขณะนี้";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
else {
$message = "ลบข้อมูลเสร็จสิ้น";
echo "<script type='text/javascript'>alert('$message');</script>";
$result = mysql_query("DELETE FROM `member` WHERE UserID= '".$id."'")
or die(mysql_error());
}
echo '<script>location = "test1.php"</script>';
}
else
{
echo "<meta http-equiv='refresh' content='0; url=test1.php'>";
// echo '<script>location = "department.php"</script>';
}
} /// end
mysql_close($conn);
?>
|
|
|
|
|
Date :
2016-07-25 10:17:02 |
By :
dudesaranyu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|