如何用按钮更新php表单和数据库的值?

时间:2014-02-21 09:39:08

标签: php sql database sql-update

所以,我有一个php表单,我添加了一个按钮来加载这个相同的表单,但我想分别更新所有字段,所以我将<td><?php echo $donnees['prenom'] ?></td>更改为<input type="hidden" value="<? echo $donnees['prenom']?>" name="prenom" />但它没有' t显示任何东西..我不知道在哪里写我的查询。 这是我的表格:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Formulaire Freelance</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="css/style.css" rel="stylesheet" type="text/css" />
    <!--    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />-->
        <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/jquery.js"></script>
    </head>
    <body style="background-color: #fff;overflow-x:scroll;"> 

    <?php
        session_start();
        if(!isset($_SESSION['login']) || $_SESSION['autoriser'] != '1'){
            header("location:connexion.php");
        }
    ?>


        <nav class="navbar navbar-default navbar-static-top " role="navigation">
          <div class="navbar-header">
            <a class="navbar-brand menuCentre" href="deconnexion.php">Se d&eacute;connecter</a>
          </div>
        </nav>

        <form method="post" action="modification-freelance.php">
        <input type="submit" class="btn btn-default" value="Modifier" name="valider" />
        <table class="table table-bordered" id="tableau">
            <thead>
                <tr class="danger">
                    <td>Pr&eacute;nom</td>
                    <td>Nom</td>
                    <td>Adresse</td>
                    <td>Code postal</td>
                    <td>Ville</td>
                    <td>T&eacute;l&eacute;phone</td>
                    <td>Email</td>
                    <td>Tarif journalier</td>
                    <td>Apparaitre sur le site ?</td>
                    <td>Pr&eacute;sentation</td>
                    <td>M&eacute;tier principal</td>
                    <td>Autres m&eacute;tier</td>
                    <td>Comp&eacute;tences</td>
                    <td>Lien de la photo</td>
                    <td>Lien du C.V</td>
                    <!--<td>Lien du R.I.B.</td>-->
                    <td colspan="3" class="text-center">Projet</td>
                    <td>Commentaires</td>


                </tr>
            </thead>
            <tbody>
    <?php
        include "AccessBddMysqli.php";
        $reponse = mysql_query("SELECT i.*, m.*, p.* FROM infofreelance i 
                                LEFT OUTER JOIN metier m ON m.id = i.idMetier 
                                LEFT OUTER JOIN projet p ON p.id = i.idProjet"
                                ) or die(mysql_error());
        while($donnees = mysql_fetch_array($reponse) ){
        /* Vérification = si il y a des fichier upload ou non.*/
                $cheminProjet = "fichier/projet/".$donnees['fichier'];
                $cheminCv = "fichier/cv/".$donnees['lienCv'];
                $cheminRib = "fichier/rib/".$donnees['lienRib'];
                $cheminPhoto = "fichier/photo/".$donnees['lienPhoto'];


            // si 0 sélectionner alors non sinon oui
            if($donnees['apparaitreSite'] == 0)
                $donnees['apparaitreSite'] = "non";
            else
                $donnees['apparaitreSite'] = "oui";

    ?>
                <tr>
                    <td><?php echo $donnees['prenom'] ?></td>
                    <td><?php echo $donnees['nom']?></td>
                    <td><?php echo $donnees['adresse']?></td>
                    <td><?php echo $donnees['codePostal']?></td>
                    <td><?php echo $donnees['ville']?></td>
                    <td><?php echo $donnees['telephone']?></td>
                    <td><?php echo $donnees['email']?></td>
                    <td><?php echo $donnees['tarifJournalier']?> &euro;</td>
                    <td><?php echo $donnees['apparaitreSite']?></td>
                    <td style="width:25em;">
                        <textarea rows="10" cols="15" class="form-control">
                            <?php echo $donnees['presentation']?>
                        </textarea><br/></td>
                    <td><?php echo $donnees['libelle']?></td>
                    <td><?php echo $donnees['autreMetier']?></td>
                    <td style="width:25em;">
                        <textarea rows="10" cols="10" class="form-control">
                            <?php echo $donnees['idCompetence']?>
                        </textarea><br/>
                    </td>
                    <td>
                    <?
                        if($cheminPhoto != "fichier/photo/"){
                    ?>
                            <a href="<?php echo $cheminPhoto ?>" class="btn btn-success" ><span class="glyphicon glyphicon-cloud-download"></span></a><br/><br/>
                            <img src="<?php echo $cheminPhoto ?>" width="50" alt="">
                    <?
                        }
                    ?>
                    </td>
                    <td>
                    <?
                        if($cheminCv != "fichier/cv/"){
                    ?>
                        <a href="<?php echo $cheminCv ?>"class="btn btn-danger"><span class="glyphicon glyphicon-cloud-download"></span></a>
                    <?
                        }
                    ?>
                    </td>
                    <!--
                    <td>
                        <?php
                        //if($cheminRib == "fichier/rib/"){
                        ?>
                        <a href="<?php //echo $cheminRib ?>"class="btn btn-default"><span class="glyphicon glyphicon-cloud-download"></a>
                        <?php
                        //}
                        //else?>
                            <span class="glyphicon glyphicon-remove-sign">

                    </td>
                    -->
                    <td><?php echo $donnees['description'] ?></td>
                    <td>
                    <?
                        if($donnees['lien'] != ""){
                    ?>
                        <a href="<?php echo $donnees['lien'] ?>"class="btn btn-warning"><span class="glyphicon glyphicon-link"></span></a>  
                    <?
                        }
                    ?>                  
                    </td>
                    <td>
                    <?
                        if($cheminProjet != "fichier/projet/"){
                    ?>
                        <a href="<?php echo $cheminProjet ?>"class="btn btn-info"><span class="glyphicon glyphicon-cloud-download"></span></a>  
                    <?
                        }
                    ?>                  
                    </td>
                    <td style="width:25em;">
                        <textarea rows="10" cols="15" class="form-control">
                            <?php echo $donnees['commentaire']?>
                        </textarea><br/>
                    </td>

                </tr>
                </tbody>
    <?php
        }
    ?>
        </table>
        </form>
    </body>

我该怎么办?     对不起我的英文

1 个答案:

答案 0 :(得分:0)

尝试在单击此更新按钮时设置会话变量

if(isset($_POST['update']))
{
$_SESSION['update']="yes";
}

在形式之前从数据库获取值

$link=mysqli_connect("localhost","root","password","dbname");
$sql = "select * from table";
$rs = mysqli_query($link, $sql);
$row = mysqli_fetch_array($rs);

然后有这样的形式

<form method="post" >
<input type="text" name="name" value="<?php if(isset($_SESSION['update'])){   echo $row['name']; } ?>"/>
<input type="text" name="age" value="<?php if(isset($_SESSION['update'])){   echo $row['age']; } ?>"/>
</form>

当你离开这个页面或做任何其他功能时也不要忘记取消这样的会话

unset($_SESSION['update']);