国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP開發(fā)簡單圖書后臺管理系統(tǒng)新書添加功能

本節(jié)來實現(xiàn)圖書后臺管理系統(tǒng)新書添加功能

基本思路是在<form>表單中添加數(shù)據(jù)

點擊提交按鍵后將添加的數(shù)據(jù)通過SQL語句INSERT?INTO增加到數(shù)據(jù)庫中

1624.png

使用給提交按鍵一個value值insert。

<td align="right" class="td_bg">
  <input type="hidden" name="action" value="insert">
  <input type="submit" name="button" id="button" value="提交" />
</td>

使用$_POST方式獲取值。使用SQL語句INSERT?INTO將新書的信息增加到數(shù)據(jù)庫中。

<?php
if($_POST['action']=="insert"){
  $SQL = "INSERT INTO yx_books (name,price,uploadtime,type,total,leave_number)
          values('".$_POST['name']."','".$_POST['price']."','".$_POST['uptime']."','".$_POST['type']."','".$_POST['total']."','".$_POST['total']."')";
  $arr=mysqli_query($link,$sql);
  if ($arr){
    echo "<script language=javascript>alert('添加成功!');window.location='add.php'</script>";
  }
  else{
    echo "<script>alert('添加失敗');history.go(-1);</script>";
  }
}
?>

當(dāng)然我們要給<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>


繼續(xù)學(xué)習(xí)
||
<?php if($_POST['action']=="insert"){ $SQL = "INSERT INTO yx_books (name,price,uploadtime,type,total,leave_number) values('".$_POST['name']."','".$_POST['price']."','".$_POST['uptime']."','".$_POST['type']."','".$_POST['total']."','".$_POST['total']."')"; $arr=mysqli_query($link,$sql); if ($arr){ echo "<script language=javascript>alert('添加成功!');window.location='add.php'</script>"; } else{ echo "<script>alert('添加失敗');history.go(-1);</script>"; } } ?>
提交重置代碼