Modification of...LOGIN

Modification of news list, new function PHP code

<?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>";
    }
}
?>

The above code is the operation of adding and modifying the database. Being proficient in the SQL statements of adding, deleting, modifying and checking will be of great help in future functions.


Next Section
<?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>"; } } ?>
submitReset Code
ChapterCourseware