在PHP中添加表单上的帖子

时间:2015-06-10 18:38:35

标签: php

当我点击添加菜单链接以填充表单中的帖子时,添加按钮不起作用。但是当我刷新页面而不点击添加菜单链接时,添加按钮效果很好。

这是菜单链接:

<ul class="sidebar-nav">                    
<li>
    <a class="collapsed" href="#sidebar-ui" data-toggle="collapse" data-parent="#sidebar">
        <span class="icon">
           <i class="glyphicon glyphicon-align-right"></i>
        </span>
        MENU

    </a>
    <ul id="sidebar-ui" class="collapse">
        <li><a href="form_ajout.php" target="content-wrap" hover="red">Ajouter</a></li>
        <li><a href="Lister.php" target="content-wrap">Afficher</a></li>
        <li><a href="modifier_BD.php" target="content-wrap">Modifier</a></li>
        <li><a href="supprimer.php" target="content-wrap">Supprimer</a></li>
        <li><a href="consulter.php" target="content-wrap">Consulter</a></li>
        <li><a href="rechercher.php" target="content-wrap">Rechercher</a></li>
        <li><a href="galerie.php" target="content-wrap">Galeries</a></li>
        <li><a href="afficher.php" target="content-wrap">Excel file</a></li>

    </ul>
</li>

以下是表格:

<form id="validation-form" class="form-horizontal form-label-left" method="post" data-parsley-priority-enabled="false" novalidate="" action="ajout_BD.php">
<fieldset>

        <div class="form-group">
            <label class="control-label col-sm-3" for="basic">NOM :</label>
            <div class="col-sm-9">
                <input type="text" id="basic" name="Nom" class="form-control " data-parsley-trigger="change" required="required" data-parsley-id="1769" placeholder="Entrez votre Nom ">
                <ul class="parsley-errors-list" id="parsley-id-1769">
                <li class="parsley-required">Champ obligatoire.</li>                                            </ul>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3" for="basic-change">
                Pr&eacute;nom :

            </label>
            <div class="col-sm-9">
                <input type="text" id="basic-change" name="Prenom" class="form-control " data-parsley-trigger="change" required="required" data-parsley-id="9306" placeholder="Entrez votre Pr&eacute;nom ">
                <ul class="parsley-errors-list filled" id="parsley-id-9306">

                <li class="parsley-required">Champ obligatoire.</li>
                </ul>
            </div>
        </div>
</fieldset>
<fieldset>

        <div class="form-group">
            <label class="control-label col-sm-3" for="email">
                E-mail
            </label>
            <div class="col-sm-9">
                <input type="email" id="email" name="Email" class="form-control " data-parsley-trigger="change" data-parsley-validation-threshold="1" required="required" data-parsley-id="2751" placeholder="Entrer votre E-mail">
                <ul class="parsley-errors-list filled" id="parsley-id-7040">
                <li class="parsley-required">Champ obligatoire.</li>
                <li class="parsley-type">Cette valeur doit correspondre &agrave; un E-mail valide.</li>
                </ul>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-sm-3" for="number">
                T&eacute;l&eacute;phone :
            </label>
            <div class="col-sm-9">
                <input type="text" id="number" name="Telephone" class="form-control" data-parsley-type="number" required="required" data-parsley-id="2157" placeholder="Entrez votre T&eacute;l&eacute;phone"><ul class="parsley-errors-list" id="parsley-id-2157"></ul>
                <ul class="parsley-errors-list filled" id="parsley-id-1434">
                <li class="parsley-required">Champ obligatoire.</li>
                </ul>                               
            </div>
        </div>

        </div>
</fieldset>

<div class="form-actions">
    <input type="submit" class="btn btn-danger btn-rounded pull-right" name="valider" value="Ajouter"/>

    <button type="button" class="btn btn-default btn-rounded" name="Annuler" ><a href="NewMenu.php">Annuler</a></button>
</div>

PS:验证表单和菜单位于同一页面中。它是法语,因此添加按钮值为 Ajouter 。添加链接菜单的值相同。

1 个答案:

答案 0 :(得分:0)

这里是填写从form_ajout.php页面发布到数据库中的信息的页面代码,此代码在另一个页面上分隔:ajout_BD.php。

<?php
//connexion à SQL et sélection de la base
include("connexion.php");


$_Nom=$_POST['Nom'];
$_Prenom = $_POST['Prenom'];
$_Email = $_POST['Email'];
$_Tel = $_POST['Telephone'];
$Date = date("Y-m-d");

if(($_Nom == "")||($_Email==""))
{
echo "vous devez remplir les champs nom et email ! <br>";
}
else
{
    $sql = "INSERT INTO etudiants (Nom, Prenom, Email, Telephone, Date) VALUES ('$_Nom','$_Prenom','$_Email','$_Tel','$Date')" ;
    mysqli_query($db,$sql);
    mysqli_close($db);

如果($ SQL){

echo "<h2>Etudiant ajout&eacute; avec succ&egrave;s !</h2>";
}

} ?&GT;