0

To create the database, I used WAMP and with the help of PhpMyAdmin. Data display problem in the database table and in the HTML table.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <style>
    body{
        background-color:#000
        
    }
    h1,h2,h3,h4,h5,h6{
            color:#fff
    }
    hr{
        border-color:#999
    }
    tr,th,td,label{
        color:#fff
    }
    input[type="text"]{
        background-color:#999;
    }
    </style>
    <title>Affichage Test</title>
</head>
<body>
    <div  class="container col-md-12">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <br>
                <h3 class="text-center">Formulaire des Résidences</h3>
                <hr>
                <br>
            </div>
        </div>
        <div class="row">
            <div class="col-md-8">
                <h3 class="text-center">Afficher les données de la BDD</h3>
                <hr>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Filiale</th>
                            <th>Société</th>
                            <th>Résidence</th>
                            <th>Res_site</th>
                            <th>Adresse</th>
                            <th>CP</th>
                            <th>Ville</th>
                            <th>Téléphone</th>
                            <th>Mobile</th>
                            <th>Mail</th>
                            <th>Nb de logts</th>
                            <th>Syndic</th>
                            <th>N°Siret</th>
                            <th>Numéro_TVA_Intracommunautaire</th>
                            <th>Capital</th>
                            <th>Code_NAF_APE</th>
                            <th>IBAN</th>
                            <th>BIC</th>
                            <td colspan="2" class="text-center" >Action</td>
                        </tr>
                        <?php
                            $serverName = "localhost";
                            $dbname = "bddtest";
                            $password = "r7c9d1!mqtC";
                            $username = "root";
                            try{   
                                if(isset($_POST['btn_Ajout']))
                                {
                                $filiale = $_POST['txtfiliale'];
                                $societe = $_POST['txtsociete'];
                                $residence = $_POST['txtresidence'];
                                $resp = $_POST['txtresp'];
                                $adresse = $_POST['txtadresse'];
                                $cp = $_POST['txtcp'];
                                $ville = $_POST['txtville'];
                                $tel = $_POST['txttel'];
                                $mobile = $_POST['txtmobile'];
                                $mail = $_POST['txtmail'];
                                $nblgts = $_POST['txtnblgts'];
                                $syndic = $_POST['txtsyndic'];
                                $siret = $_POST['txtsiret'];
                                $tva = $_POST['txttva'];
                                $capital = $_POST['txtcapital'];
                                $code = $_POST['txtcode'];
                                $iban = $_POST['txtiban'];
                                $bic = $_POST['txtbic'];
                                
                                // Connexion à la base de données
                                $dbco = new PDO("mysql:host=$serverName;dbname=$dbname",$username,$password);
                                $dbco->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                echo "Connexion réussi";
                                //On récupère les infos de la table 
                                $sth = $dbco->prepare("SELECT (Filiale, Societe, Residences, Resp_residence, Adresse, CP, Ville, Telephone, Mobile, Mail, Nb_de_logts, Syndic, N_Siret, Numero_TVA_Intracommunautaire, Capital, Code_NAF_APE, IBAN, BIC) FROM residences");
                                $sth->execute();

                                //On affiche le résultat dans un tableau
                                while($donnees = $sth->fetch()){
                                    //On affiche toutes les informations des residences
                                    echo"<tr";
                                    echo"</th> $donnees[Filiale]<th>";
                                    echo"</th> $donnees[Société]<th>";
                                    echo"</th> $donnees[Résidence]<th>";
                                    echo"</th> $donnees[Res_site]<th>";
                                    echo"</th> $donnees[Adresse]<th>";
                                    echo"</th> $donnees[CP]<th>";
                                    echo"</th> $donnees[Ville]<th>";
                                    echo"</th> $donnees[Téléphone]<th>";
                                    echo"</th> $donnees[Mobile]<th>";
                                    echo"</th> $donnees[Mail]<th>";
                                    echo"</th> $donnees[Nb_de_logts]<th>";
                                    echo"</th> $donnees[Syndic]<th>";
                                    echo"</th> $donnees[N°Siret]<th>";
                                    echo"</th> $donnees[Numéro_TVA_Intracommunautaire]<th>";
                                    echo"</th> $donnees[Capital]<th>";
                                    echo"</th> $donnees[Code_NAF_APE]<th>";
                                    echo"</th> $donnees[IBAN]<th>";
                                    echo"</th> $donnees[BIC]<th>";
                                    echo"</tr";
                                }

                                // Insertion des données dans la table
                                $sth = $dbco->prepare("INSERT INTO residences(Filiale, Societe, Residences, Resp_residence, Adresse, CP, Ville, Telephone, Mobile, Mail, Nb_de_logts, Syndic, N_Siret, Numero_TVA_Intracommunautaire, Capital, Code_NAF_APE, IBAN, BIC) VALUES($filiale, $societe, $residence, $resp, $adresse, $cp, $ville, $tel, $mobile, $mail, $nblgts, $syndic, $siret, $tva, $capital, $code, $iban, $bic)");
                                $sth->execute($filiale, $societe, $residence, $resp, $adresse, $cp, $ville, $tel, $mobile, $mail, $nblgts, $syndic, $siret, $tva, $capital, $code, $iban, $bic);
                                echo "Insertion réussi";

                                }
                                
                            }
                            catch(PDOException $e){
                                echo 'Impossible de traiter les données. Erreur : '.$e->getMessage();
                            }
                        ?>
                    </thead>
                    <tbody>
                            <td><a href="#" class="btn btn-danger">Supprimer</a></td>
                            <td><a href="#" class="btn btn-info">Modifier</a></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <div class="col-md-4">
                <h3 class="text-center">Ajouter des Résidences</h3>
                <hr>
                <form method="post" action="">
                    <div class="form-row">
                        <div class="form-group col-md-3">
                        <label>Filiale :</label>
                        <select class="form-control" name="txtfiliale" >
                            <option value="Tourisme">Tourisme</option>
                            <option value="Etudiants">Etudiants</option>
                            <option value="Affaires">Affaires</option>
                        </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Société :</label>
                        <input type="text" name="txtsociete" class="form-control" placeholder="Tapez la société" value="societe"> </input>
                    </div>
                    <div class="form-group">
                        <label>Résidence :</label>
                        <input type="text" name="txtresidence" class="form-control" placeholder="Tapez le nom de la résidence"> </input>
                    </div>
                    <div class="form-group">
                        <label>Responsable de résidence :</label>
                        <input type="text" name="txtresp" class="form-control" placeholder="Tapez le Responsable de site"> </input>
                    </div>
                    <div class="form-group">
                        <label>Adresse :</label>
                        <input type="text" name="txtadresse" class="form-control" placeholder="Tapez l'adresse"> </input>
                    </div>
                    <div class="form-group">
                        <label>Code Postal :</label>
                        <input type="text" name="txtcp" class="form-control" placeholder="Tapez le code postal"> </input>
                    </div>
                    <div class="form-group">
                        <label>Ville :</label>
                        <input type="text" name="txtville" class="form-control" placeholder="Tapez la ville"> </input>
                    </div>
                    <div class="form-group">
                        <label>Téléphone :</label>
                        <input type="text" name="txttel" class="form-control" placeholder="Tapez le téléphone"> </input>
                    </div>
                    <div class="form-group">
                        <label>Mobile :</label>
                        <input type="text" name="txtmobile" class="form-control" placeholder="Tapez le mobile"> </input>
                    </div>
                    <div class="form-group">
                        <label>Mail :</label>
                        <input type="text" name="txtmail" class="form-control" placeholder="Tapez le mail"> </input>
                    </div>
                    <div class="form-group">
                        <label>Nombre de logement :</label>
                        <input type="text" name="txtnblgts" class="form-control" placeholder="Tapez le nombre de logements"> </input>
                    </div>
                    <div class="form-group">
                        <label>Syndic :</label>
                        <input type="text" name="txtsyndic" class="form-control" placeholder="Tapez le syndic"> </input>
                    </div>
                    <div class="form-group">
                        <label>N°Siret :</label>
                        <input type="text" name="txtsiret" class="form-control" placeholder="Tapez le numéro de siret "> </input>
                    </div>
                    <div class="form-group">
                        <label>Numéro TVA Intracommuanuataire :</label>
                        <input type="text" name="txttva" class="form-control" placeholder="Tapez le numéro de TVA intracommunautaire"> </input>
                    </div>
                    <div class="form-group">
                        <label>Capital :</label>
                        <input type="text" name="txtcapital" class="form-control" placeholder="Tapez le capital"> </input>
                    </div>
                    <div class="form-group">
                        <label>Code NAF/APE :</label>
                        <input type="text" name="txtcode" class="form-control" placeholder="Tapez le code NAF/APE"> </input>
                    </div>
                    <div class="form-group">
                        <label>IBAN :</label>
                        <input type="text" name="txtiban" class="form-control" placeholder="Tapez l'Iban"> </input>
                    </div>
                    <div class="form-group">
                        <label>BIC :</label>
                        <input type="text" name="txtbic" class="form-control" placeholder="Tapez le Bic"> </input>
                    </div>
                    <div class="form-group">
                        <input type="submit" name="btn_Ajout" class="btn btn-primary btn-block" value="Enregistrer"></input>
                        <hr>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html>

Error message :

Connexion réussiImpossible de traiter les données. Erreur : SQLSTATE[42000]: Syntax error or access violation: 1064 Erreur de syntaxe pr�s de ' , , , , , , , , , , , , , , )' � la ligne 1

  • [Posts on Stack Overflow have to be in English](https://meta.stackexchange.com/q/13676). Please [edit] the post to translate everything. A ratatouille of various languages in the same sentence is rather bad for comprehensibility, even if you speak both languages. – Adriaan Dec 16 '22 at 09:25
  • it's ok for you? i'm sorry. – serviceitnemea Dec 16 '22 at 09:28
  • You need to follow the required syntax rules instead of inventing your own. Please learn how to use PDO properly, for example here on my site: https://phpdelusions.net/pdo_examples/insert – Your Common Sense Dec 16 '22 at 09:29
  • Also, you should separate the code that displays the table from code that does insert. Right now they are entangled. You r problem is clearly in the INSERT query while you are asking about SELECT. Why not to learn how to use PDO on a simpler table that has only one or two columns? And only then go for such a big table – Your Common Sense Dec 16 '22 at 09:32
  • Please read [How to include a PHP variable inside a MySQL statement](https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement) and look more carefully at the examples - you're binding parameters, but you haven't defined any placeholders for them! And also study the basics of SQL syntax in general. – ADyson Dec 16 '22 at 09:32

0 Answers0