Tutoriel de sit...SE CONNECTER

Tutoriel de site Web d'entreprise de développement PHP : Ajouter des informations sur l'actualité

Cliquez sur le bouton Ajouter pour accéder à la page addne.php

Jetons un coup d'œil au code addne.php :

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加新闻资讯</title>
    <style type="text/css">
        .ipt{width:180px;height:30px;border-radius:5px;
            outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;}
        .txt{width:250px;height:200px;}
        .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;}
    </style>
</head>
<body>
    <form method="post" action="addnews.php">
        标题:<input type="text" name="title" class="ipt">
        </br></br>
        内容:<textarea cols="50" rows="5" name="content" class="txt"></textarea></br></br>
        <select name="type">
            <option value="0">公司公告</option>
            <option value="1">公司新闻</option>
        </select>
        </br></br>
        <input type="submit" value="添加" class="sub">
    </form>
</body>
</html>

Regardez le code ci-dessus : soumission du formulaire addnews.php

Regardons le code de la page addnews.php suivante :

<?php
    //添加新闻资讯
    require_once('conn.php');
    $title=$_POST['title'];
    $content = $_POST['content'];
    $type = $_POST['type'];
    $newtime = time();

    $sql  = "insert into `news`(title,type,content,newtime) values('$title','$type','$content','$newtime')";
    $res = mysql_query($sql);
    if($res){
        echo "<script>alert('添加新闻成功');location.href='news.php';</script>";
    }else{
        echo "<script>alert('添加新闻失败');location.href='news.php';</script>";
    }

?>

Obtenez les informations du formulaire, puis ajoutez-les à la table de la base de données, puis jugez si elles ont été ajoutées avec succès

section suivante
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>添加新闻资讯</title> <style type="text/css"> .ipt{width:180px;height:30px;border-radius:5px; outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;} .txt{width:250px;height:200px;} .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;} </style> </head> <body> <form method="post" action="addnews.php"> 标题:<input type="text" name="title" class="ipt"> </br></br> 内容:<textarea cols="50" rows="5" name="content" class="txt"></textarea></br></br> <select name="type"> <option value="0">公司公告</option> <option value="1">公司新闻</option> </select> </br></br> <input type="submit" value="添加" class="sub"> </form> </body> </html>
soumettreRéinitialiser le code
chapitredidacticiel