IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Connexion PHP MySQL [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 3
    Par défaut Connexion PHP MySQL
    Bonjour,
    j'utilise les codes suivant

    news_db.inc.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    <?php
    # database connection #									
    $db = 'nom_bd';
    $dbuser = 'nom_utilissateur';
    $dbpass = 'mot_de_passe';
    $dbhost = 'localhost:3306';
     
    mysql_connect($dbhost,$dbuser,$dbpass) or die("impossible de faire la connexion");
    mysql_select_db("$db") or die("impossible d'ouvrir la base de donnée");
    ?>
    et le formulaire de saisie

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
     
    <head>
    <title>Formulair Adhésion</title>
    <meta http-equiv="Content-Type" content="text/php; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
    <table width="747" height="589" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
    	<tr>
    		<td colspan="11">
    			<img src="../images/index_01.gif" width="746" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="1" alt=""></td>
    	</tr>	<tr>
    		<td rowspan="3">
    			<img src="../images/index_02.gif" width="96" height="100" alt=""></td>
    		<td colspan="10" rowspan="2" align="left" valign="top">&nbsp;</td>
      <td>
    			<img src="../images/spacer.gif" width="1" height="63" alt=""></td>
    	</tr>
    	<tr>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="1" alt=""></td>
    	</tr>
    	<tr>
    		<td colspan="5" align="left" valign="top">
            </td>
    		<td colspan="4" align="left" valign="top">
            </td>
    		<td>
    			<img src="../images/index_09.gif" width="150" height="36" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="36" alt=""></td>
    	</tr>
    	<tr>		<td width="96" rowspan="15" align="left" valign="top"><p></p>
    <td width="22" rowspan="18" align="left" valign="top" background="../images/color_leftside.gif">
    			<img src="../images/color_upperleft.gif" width="22" height="13" alt=""></td>
    		<td colspan="6" rowspan="18" align="left" valign="top">
    		  <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    <form method="POST" action="verif_adhesion.php">
     
    <fieldset id="coordonnees">
      <table border="0" cellspacing="3" cellpadding="0">
        <tr>
          <td>
            <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">Adhésion
            :</td>
          <td>
            <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
        <input type="text" name="adhe" size="55" /></td>
        </tr>
      </table>
    </fieldset>
     
    <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
      <input type="submit" value="Envoyer" />
      <input type="reset" value="Recommencer" />
    </p>
     
    </form>
    		  <table width="100%" border="0">
                <tr>
                  <td><div align="center">
                      <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">&nbsp;</div></td>
                </tr>
              </table>	  </td>
    		<td colspan="2" rowspan="18" align="left" valign="top" background="../images/color_rightside.gif">
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/color_upperright.gif" width="25" height="14" alt=""></p>
          </td>
    		<td width="150" rowspan="13" align="left" valign="top"><p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">&nbsp;</p>
    	    <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">&nbsp;</p></td>
      <td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="13" alt=""></p>
          </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="1" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="5" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="17" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="2" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="19" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td rowspan="8" valign="bottom">
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
                </p>
            </td>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="44" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="152" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td rowspan="6">
    			<img src="../images/index_29.gif" width="96" height="101" alt=""></td>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="23" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="1" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td>
                <p style="word-spacing: 0; text-indent: 0; line-height: 100%; margin: 0">
    			<img src="../images/spacer.gif" width="1" height="5" alt=""></p>
            </td>
    	</tr>
    	<tr>
    		<td colspan="2" align="left" valign="top">
    			<img src="../images/color_bottomleft.gif" width="29" height="33" alt=""></td>
    		<td colspan="4" align="left" valign="top">
    			<img src="../images/bottom_bar.gif" width="442" height="33" alt=""></td>
    		<td colspan="3" align="left" valign="top">
    			<img src="../images/color_bottomright.gif" width="29" height="33" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="33" alt=""></td>
    	</tr>
    	<tr>
    		<td colspan="3" align="left" valign="top"></td>
    		<td colspan="6" align="left" valign="top">
            </td>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="36" alt=""></td>
    	</tr>
    	<tr>
    		<td colspan="9">
    			<img src="../images/index_37.gif" width="500" height="3" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="3" alt=""></td>
    	</tr>
    	<tr>
    		<td>
    			<img src="../images/spacer.gif" width="96" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="22" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="7" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="86" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="72" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="218" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="66" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="4" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="24" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="1" height="1" alt=""></td>
    		<td>
    			<img src="../images/spacer.gif" width="150" height="1" alt=""></td>
    		<td></td>
    	</tr>
    </table>
     
    </body>
    et finalement dans une autre page je fait la vérification et j'injecte dans la BD

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
    <?php
    require ('news_db.inc.php');
     
     
    $msg_erreur = "Erreur. Les champs suivants doivent être obligatoirement remplis :<br/><br/>";
    $msg_ok = "Votre demande a bien été prise en compte. <br/>";
    $message = $msg_erreur;
     
    // vérification des champs 
    if (empty($_POST['adhe'])) 
      $message .= "Saisie un type d'adhésion<br/>";
     
    // si un champ est vide, on affiche le message d'erreur 
    if (strlen($message) > strlen($msg_erreur)) {
     
      echo $message;
     
    // sinon c'est ok 
    } else {
    foreach($_POST as $index => $valeur) 
    {
        $$index = mysql_real_escape_string(trim($valeur));
    }
    $sql = "INSERT INTO t_adhesion VALUES ('', '".$adhe."')";
      $res = mysql_query($sql);
     
      if ($res) {
        echo $msg_ok, echo $_POST['adhe'];
      }
      else {
        echo mysql_error();
      }
    }
    mysql_close();
    ?>
    normalement je doit avoir un message soit que l'enregistrement est bin ajouter ou non mais j'ai une page blanche comme résultat et rien ne s'ajoute dans la base.

    quelqu'un peut m'aider

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Bonjour,

    Il y a une faute :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo $msg_ok; echo $_POST['adhe'];
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 3
    Par défaut
    3 jours de lecture et je l'ai pas vu

    merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Connexion PHP à MySQL dans serveur Wamp
    Par miloko dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 29/12/2013, 04h27
  2. Connexion à PHP MySQL
    Par BoyzInDaProject dans le forum EDI/Outils
    Réponses: 1
    Dernier message: 20/07/2010, 10h28
  3. [MySQL] connexion PHP-MYSQL
    Par marty499 dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 13/12/2009, 20h26
  4. [MySQL] Connexion PHP/MYSQL
    Par Stass dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 08/08/2008, 13h19
  5. [MySQL] Connexion PHP / MySQL
    Par Erwan M. dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 06/08/2008, 16h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo