PHP开发简单图书后台管理系统新书管理修改删除功能

本节讲解“新书管理”页面选择点击操作功能里面的“修改”,“删除”功能的实现

先说“删除”功能。

主要的思路是:

获取要删除的书籍的id

46.png

通过SQL语句删除此书的id来删除此id在数据库中的的全部记录。

<?php
$SQL ="DELETE FROM yx_books where id='".$_GET['id']."'";
$arry=mysqli_query($link,$sql);
if($arry){
  echo "<script> alert('删除成功');location='list.php';</script>";
}
else
  echo "删除失败";
?>

然后是“修改”功能。

1623.png

获取需要修改书籍的id

通过SQL语句查询数据库中此条id的所有信息。再通过SQL语句修改此条id的信息

<?php
$SQL = "SELECT * FROM yx_books where id='".$_GET['id']."'";
$arr=mysqli_query($link,$sql);
$rows=mysqli_fetch_row($arr);
?>
<?php
if($_POST['action']=="modify"){
  $sqlstr = "UPDATE yx_books SET name = '".$_POST['name']."', price = '".$_POST['price']."', uploadtime = '".$_POST['uptime']."', 
  type = '".$_POST['type']."', total = '".$_POST['total']."' where id='".$_GET['id']."'";
  $arry=mysqli_query($link,$sqlstr);
  if ($arry){
    echo "<script> alert('修改成功');location='list.php';</script>";
  }
  else{
    echo "<script>alert('修改失败');history.go(-1);</script>";
  }

}
?>

给<from>表单一个onSubmit点击事件:

<form id="myform" name="myform" method="post" action="" onSubmit="return myform_Validator(this)">

通过onSubmit点击事件用<javascript>判断修改书籍信息时不能让每项修改的信息为空。

<script type="text/javascript">
  function myform_Validator(theForm)
  {

    if (theForm.name.value == "")
    {
      alert("请输入书名。");
      theForm.name.focus();
      return (false);
    }
    if (theForm.price.value == "")
    {
      alert("请输入书名价格。");
      theForm.price.focus();
      return (false);
    }
    if (theForm.type.value == "")
    {
      alert("请输入书名所属类别。");
      theForm.type.focus();
      return (false);
    }
    return (true);
  }
</script>


继续学习
||
<?php $SQL = "SELECT * FROM yx_books where id='".$_GET['id']."'"; $arr=mysqli_query($link,$sql); $rows=mysqli_fetch_row($arr); ?> <?php if($_POST['action']=="modify"){ $sqlstr = "UPDATE yx_books SET name = '".$_POST['name']."', price = '".$_POST['price']."', uploadtime = '".$_POST['uptime']."', type = '".$_POST['type']."', total = '".$_POST['total']."' where id='".$_GET['id']."'"; $arry=mysqli_query($link,$sqlstr); if ($arry){ echo "<script> alert('修改成功');location='list.php';</script>"; } else{ echo "<script>alert('修改失败');history.go(-1);</script>"; } } ?>
提交重置代码
章节
笔记
提问
课件
反馈
捐赠

PHP开发之简单图书后台管理系统教程