亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Pengubahsuaian senarai berita, kod PHP fungsi baru

<?php
 header("content-type:text/html;charset=utf-8");
 $link = mysqli_connect('localhost','root','root','news');
 mysqli_set_charset($link, "utf8");
 if (!$link) {
     die("連接失敗:".mysqli_connect_error());
 }
 //接收id值
$id = isset($_GET['id'])?$_GET['id']:'';
//判斷id是否有值,有值:執(zhí)行查詢當(dāng)前需編輯的新聞內(nèi)容
if($id){
    $sqlS = "select title,content,author from new where id={$id}";
    $ret = mysqli_query($link, $sqlS);
    $row = mysqli_fetch_assoc($ret);
}
if($_POST){
    $title = isset($_POST['title'])?$_POST['title']:"";
    $author = isset($_POST['author'])?$_POST['author']:"";
    $content = isset($_POST['content'])?$_POST['content']:"";
    if($id){
        $sql = "update new set title = '$title',author = '$author',content = '$content',update_at = date(curtime()) where id = '$id'";
        $tips = "更新成功";
    }else{
        $sql = "insert into new(title,content,author,create_at) values('{$title}','{$content}','{$author}',date(curtime()))";
        $tips = "添加成功";
    }
    //執(zhí)行sql
    $result = mysqli_query($link, $sql);
    if($result){
        echo "<script>alert('添加成功');window.location.href='lists.php'</script>";
    }else{
        echo "<script>alert('操作失敗');window.location.href='xgai.php'</script>";
    }
}
?>

Kod di atas ialah operasi menambah dan mengubah suai pangkalan data Mahir dalam penyataan SQL untuk menambah, memadam, mengubah suai dan menyemak akan sangat membantu dalam fungsi masa hadapan.


Meneruskan pembelajaran
||
<?php header("content-type:text/html;charset=utf-8"); $link = mysqli_connect('localhost','root','root','news'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } //接收id值 $id = isset($_GET['id'])?$_GET['id']:''; //判斷id是否有值,有值:執(zhí)行查詢當(dāng)前需編輯的新聞內(nèi)容 if($id){ $sqlS = "select title,content,author from new where id={$id}"; $ret = mysqli_query($link, $sqlS); $row = mysqli_fetch_assoc($ret); } if($_POST){ $title = isset($_POST['title'])?$_POST['title']:""; $author = isset($_POST['author'])?$_POST['author']:""; $content = isset($_POST['content'])?$_POST['content']:""; if($id){ $sql = "update new set title = '$title',author = '$author',content = '$content',update_at = date(curtime()) where id = '$id'"; $tips = "更新成功"; }else{ $sql = "insert into new(title,content,author,create_at) values('{$title}','{$content}','{$author}',date(curtime()))"; $tips = "添加成功"; } //執(zhí)行sql $result = mysqli_query($link, $sql); if($result){ echo "<script>alert('添加成功');window.location.href='lists.php'</script>"; }else{ echo "<script>alert('操作失敗');window.location.href='xgai.php'</script>"; } } ?>