Pengubahsuaian ...LOG MASUK

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是否有值,有值:执行查询当前需编辑的新闻内容
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 = "添加成功";
    }
    //执行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.


bahagian seterusnya
<?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是否有值,有值:执行查询当前需编辑的新闻内容 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 = "添加成功"; } //执行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>"; } } ?>
babperisian kursus