Thursday, 13 January 2022

PHP#18MySQL#14 - Thêm, Xóa, Sửa, Lọc theo ngôn ngữ, lọc theo thể loại, loại

 //theloai.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Thể Loại</title>
</head>

<body>
<?php
include("../connect.php");
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang="vi";
?>
<form method="get" id="form1" name="form1">
  <p>
    <label for="select">Chọn ngôn ngữ:</label>
    <select name="lang" id="lang" onChange="form1.submit();">
      <option value="vi">Việt</option>
      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
</form>
<table width="700" border="1" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <th scope="col">Thứ tự</th>
      <th scope="col">Tên thể loại</th>
      <th scope="col">Tên không dấu</th>
      <th scope="col">Trạng thái</th>
      <th scope="col"><a href="theloai_them.php?lang=<?php echo $lang;?>">Thêm</a></th>
    </tr>
    <?php 
$sl="select * from theloai where lang='$lang' order by ThuTu";
$kq=mysqli_query($link,$sl);
while($d=mysqli_fetch_array($kq)){
?>
    <tr>
      <td><?php echo $d['ThuTu'];?></td>
      <td><?php echo $d['TenTL'];?></td>
      <td><?php echo $d['TenTL_KhongDau'];?></td>
      <td><?php if($d['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>
      <td><a href="process.php?xoatl=<?php echo $d['idTL']?>&lang=<?php echo $lang;?>" onClick="return confirm('Bạn có muốn xóa thể loại này không?')";>Xóa</a>/<a href="theloai_sua.php?idTL=<?php echo $d['idTL']?>&lang=<?php echo $lang;?>">Sửa</a></td>
    </tr>
    <?php }?>
  </tbody>
</table>

</body>
</html>

//theloai_them.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php 
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang="vi";
?>
<form method="post" id="form1" name="form1" action="process.php">
  <p>
    <label for="lang">Ngôn ngữ:</label>
    <select name="lang" id="lang">
      <option value="vi">Việt</option>
      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
  <p>
    <label for="ThuTu">Thứ tự:</label>
    <input name="ThuTu" type="text" id="ThuTu" size="5">
  </p>
  <p>
    <label for="TenTL">Tên TL:</label>
    <input type="text" name="TenTL" id="TenTL">
  </p>
  <p>
    <label for="TenTL_KhongDau">Tên KD:</label>
    <input type="text" name="TenTL_KhongDau" id="TenTL_KhongDau">
  </p>
  <p>
    <label for="AnHien">Trạng thái:</label>
    <select name="AnHien" id="AnHien">
      <option value="0">Ẩn</option>
      <option value="1">Hiện</option>
    </select>
  </p>
  <p>
    <input type="submit" name="themtl" id="themtl" value="Thêm">
  </p>
</form>
</body>
</html>


//theloai_sua.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_GET['idTL']))
$idTL=$_GET['idTL'];
include("../connect.php");
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang="vi";
$sl="select * from theloai where idTL=$idTL";
$kq=mysqli_query($link,$sl);
$d=mysqli_fetch_array($kq);
?>
<form method="post" id="form1" name="form1" action="process.php">
  <p>
    <label for="lang">Ngôn ngữ:</label>
    <select name="lang" id="lang">
      <option value="vi">Việt</option>
      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
  <p>
    <label for="ThuTu">Thứ tự:</label>
    <input name="ThuTu" type="text" id="ThuTu" size="5" value="<?php echo $d['ThuTu'];?>">
  </p>
  <p>
    <label for="TenTL">Tên TL:</label>
    <input type="text" name="TenTL" id="TenTL" value="<?php echo $d['TenTL'];?>">
  </p>
  <p>
    <label for="TenTL_KhongDau">Tên KD:</label>
    <input type="text" name="TenTL_KhongDau" id="TenTL_KhongDau" value="<?php echo $d['TenTL_KhongDau'];?>">
  </p>
  <p>
    <label for="AnHien">Trạng thái:</label>
    <select name="AnHien" id="AnHien">
      <option value="0">Ẩn</option>
      <option value="1" <?php  if($d['AnHien']) echo "selected";?>>Hiện</option>
    </select>
  </p>
  <p>
  <input type="hidden" name="idTL" id="idTL" value="<?php echo $d['idTL'];?>">
    <input type="submit" name="suatl" id="suatl" value="Cập nhật">
  </p>
</form>
<?php }?>
</body>
</html>

//loaitin.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Loại Tin</title>
</head>

<body>
<?php
include("../connect.php");
if(isset($_GET['lang'])) $lang=$_GET['lang'];
else $lang="vi";
?>
<form method="get" id="form1" name="form1">
  <p>
    <label for="loaitin">Chọn ngôn ngữ:</label>
    <select name="lang" id="lang" onChange="form1.submit();">
      <option value="vi">Việt</option>
      <option value="en"<?php if($lang=="en") echo "selected";?>>English</option>
    </select>
  </p>
  <p>
    <label for="theloai">Thể loại:</label>
    <select name="theloai" id="theloai" onChange="form1.submit();">
<?php 
$sl="select * from theloai where lang='$lang' order by ThuTu";
$kq=mysqli_query($link,$sl);
$idTL=0;
while($d=mysqli_fetch_array($kq))
{
if($idTL==0) $idTL=$d['idTL'];
?>
      <option value="<?php echo $d['idTL'];?>"<?php if(isset($_GET['theloai'])&&$_GET['theloai']==$d['idTL']) {echo "selected"; $idTL=$_GET['theloai'];}?>><?php echo $d['TenTL'];?></option>
      <?php }?>
    </select>
  </p>
</form>
<table width="700" border="1" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <th scope="col">Thứ tự</th>
      <th scope="col">Tên loại</th>
      <th scope="col">Tên không dấu</th>
      <th scope="col">Trạng thái</th>
      <th scope="col"><a href="loaitin_them.php?lang=<?php echo $lang;?>">Thêm</a></th>
    </tr>
    <?php 
$sl="select * from loaitin where idTL=$idTL order by ThuTu";
$kq=mysqli_query($link,$sl);
while($d=mysqli_fetch_array($kq)){
?>
    <tr>
      <td><?php echo $d['ThuTu'];?></td>
      <td><?php echo $d['Ten'];?></td>
      <td><?php echo $d['Ten_KhongDau'];?></td>
      <td><?php if($d['AnHien']) echo "Hiện"; else echo "Ẩn";?></td>
      <td><a href="process.php?xoalt=<?php echo $d['idLT']?>&lang=<?php echo $lang;?>" onClick="return confirm('Bạn có muốn xóa thể loại này không?')";>Xóa</a>/<a href="loaitin_sua.php?idLT=<?php echo $d['idLT']?>&lang=<?php echo $lang;?>">Sửa</a></td>
    </tr>
    <?php }?>
  </tbody>
</table>

</body>
</html>


//process.php

<?php 
include("../connect.php");
if(isset($_POST['themtl']))
{
$sl="insert into theloai values(NULL,'{$_POST['lang']}', '{$_POST['TenTL']}', '{$_POST['TenTL_KhongDau']}', {$_POST['ThuTu']}, {$_POST['AnHien']})";
if(mysqli_query($link,$sl))
header("location:theloai.php?lang=".$_POST['lang']);
else echo $sl;
}
//Xửa lý sửa 1 thể loại:
if(isset($_POST['suatl']))
{
$sl="update theloai set lang='{$_POST['lang']}', TenTL='{$_POST['TenTL']}', TenTL_KhongDau='{$_POST['TenTL_KhongDau']}',
ThuTu={$_POST['ThuTu']}, AnHien={$_POST['AnHien']} where idTL={$_POST['idTL']}";
if($kq=mysqli_query($link,$sl))
header("location:theloai.php?lang=".$_POST['lang']);
else echo $sl;
}
//Xử lý xóa 1 thể loại:
if(isset($_GET['xoatl']))
{
$sl="delete from theloai where idTL=".$_GET['xoatl'];
if($kq=mysqli_query($link,$sl))
header("location:theloai.php?lang=".$_GET['lang']);
else echo $sl;
}
?>

0 comments:

Post a Comment