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

Langage PHP Discussion :

[Tableaux] Problème sur formulaire, enregistrement dans BD


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mars 2008
    Messages : 3
    Points : 2
    Points
    2
    Par défaut [Tableaux] Problème sur formulaire, enregistrement dans BD
    Salut tout le monde,

    Pour un examen pratique je dois réaliser un site annuaire ou des clients peuvent s'inscrire et ensuite être trouvés par le biais d'un champs de recherche. Le site comporte donc une base de données.

    Mon problème est que je n'arrive pas à mettre en place le formulaire avec l'enregistrement dans la base de données. Lorsque je vais sur le site la page d'enregistrement me donne l'erreur Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 31

    Est-ce que quelqu'un pourrait m'aider ?

    Voici le code du formulaire:
    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     
    <html>
     
    	<head>
    		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    		<meta name="generator" content="Adobe GoLive">
    		<title>Registration</title>
    		<link href="style.css" rel="stylesheet" type="text/css" media="all">
    		<csscriptdict import>
    			<script type="text/javascript" src="GeneratedItems/CSScriptLib.js"></script>
    		</csscriptdict>
    		<csactiondict>
    			<script type="text/javascript"><!--
    var preloadFlag = false;
    function preloadImages() {
    	if (document.images) {
    		pre_img_Calque_1_down = newImage('images/registration_button.data_/img_Calque-1-down.gif');
    		preloadFlag = true;
    	}
    }
     
    // --></script>
    		</csactiondict>
    	</head>
     
    	<body onload="preloadImages();" bgcolor="#ffffff" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
    		<div align="center">
    			<table width="265" border="0" cellspacing="0" cellpadding="0">
    				<tr height="37">
    					<td height="37"></td>
    				</tr>
    				<tr height="52">
    					<td height="52"><img src="images/title_registration.jpg" alt="" height="52" width="364" border="0"></td>
    				</tr>
    			</table>
    			<form action="register.php" method="post" target="_self">
    				<table width="513" border="0" cellspacing="0" cellpadding="0">
    					<tr>
    						<td valign="top">
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="42">
    									<td align="left" valign="middle" width="124" height="42"></td>
    									<td align="left" valign="middle" width="30" height="42"></td>
    									<td align="left" valign="middle" width="359" height="42"></td>
    								</tr>
    								<tr>
    									<td align="left" valign="middle" width="124">
    										<div align="right">
    											<img src="images/labels/activities.gif" alt="" height="17" width="117" border="0"></div>
    									</td>
    									<td align="left" valign="middle" width="30"></td>
    									<td align="left" valign="middle" width="359">
    										<div class="textfield">
    											<p><input class="textfield" type="text" name="activities" size="44"></p>
    										</div>
    									</td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="22">
    									<td width="113" height="22"></td>
    									<td width="44" height="22"></td>
    									<td width="276" height="22"></td>
    								</tr>
    								<tr>
    									<td width="113">
    										<div align="right">
    											<img src="images/labels/society.gif" alt="" height="21" width="91" border="0"></div>
    									</td>
    									<td width="44"></td>
    									<td class="textfield" width="276"><input class="textfield" type="text" name="society" size="43"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="40">
    									<td width="108" height="40"></td>
    									<td width="27" height="40"></td>
    									<td width="276" height="40"></td>
    								</tr>
    								<tr>
    									<td width="108">
    										<div align="right">
    											<img src="images/labels/address.gif" alt="" height="17" width="99" border="0"></div>
    									</td>
    									<td width="27"></td>
    									<td class="textfield" width="276"><input class="textfield" type="text" name="adress1" size="44"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="14">
    									<td width="108" height="14"></td>
    									<td width="53" height="14"></td>
    									<td width="276" height="14"></td>
    								</tr>
    								<tr>
    									<td width="108">
    										<div align="right"></div>
    									</td>
    									<td width="53"></td>
    									<td class="textfield" width="276"><input class="textfield" type="text" name="adress2" size="44"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="36">
    									<td width="108" height="36"></td>
    									<td width="27" height="36"></td>
    									<td width="276" height="36"></td>
    								</tr>
    								<tr>
    									<td width="108">
    										<div align="right">
    											<img src="images/labels/country.gif" alt="" height="20" width="95" border="0"></div>
    									</td>
    									<td width="27"></td>
    									<td class="textfield" width="276"><input class="textfield" type="text" name="country" size="44"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="40">
    									<td width="203" height="40"></td>
    									<td width="20" height="40"></td>
    									<td width="276" height="40"></td>
    								</tr>
    								<tr>
    									<td width="203">
    										<div align="right">
    											<img src="images/labels/email.gif" alt="" height="18" width="176" border="0"></div>
    									</td>
    									<td width="20"></td>
    									<td class="textfield" width="276"><input class="textfield" type="text" name="email" size="44"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="47">
    									<td width="99" height="47"></td>
    									<td width="27" height="47"></td>
    									<td width="276" height="47"></td>
    								</tr>
    								<tr>
    									<td width="99">
    										<div align="right">
    											<img src="images/labels/web.gif" alt="" height="17" width="49" border="0"></div>
    									</td>
    									<td width="27"></td>
    									<td class="textfield" width="276"><input class="textfield" type="text" name="web" size="44"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="50">
    									<td width="116" height="50"></td>
    									<td width="17" height="50"></td>
    									<td width="276" height="50"></td>
    								</tr>
    								<tr>
    									<td width="116">
    										<div align="right">
    											<img src="images/labels/password.gif" alt="" height="21" width="118" border="0"></div>
    									</td>
    									<td width="17"></td>
    									<td class="textfield" width="276"><input class="textfield" type="password" name="password" size="44"></td>
    								</tr>
    							</table>
    							<table border="0" cellspacing="0" cellpadding="0">
    								<tr height="37">
    									<td width="312" height="37"></td>
    									<td width="24" height="37"></td>
    									<td width="158" height="37"></td>
    								</tr>
    								<tr>
    									<td class="textfield" width="312">
    										<div align="right">
    											<input class="textfield" type="password" name="confirmation" size="44"></div>
    									</td>
    									<td width="24"></td>
    									<td width="158"><img src="images/labels/confirmation.gif" alt="" height="18" width="158" border="0"></td>
    								</tr>
    							</table>
    							<br>
    							<br>
    							<table width="512" border="0" cellspacing="0" cellpadding="0">
    								<tr>
    									<td>
    										<div align="center">
    											<a onmousedown="changeImages('img_Calque_1','images/registration_button.data_/img_Calque-1-down.gif');return true" onmouseup="changeImages('img_Calque_1','images/registration_button.data_/img_Calque-1.gif');return true" onmouseout="changeImages('img_Calque_1','images/registration_button.data_/img_Calque-1.gif');return true"><input id="img_Calque_1" type="image" src="images/registration_button.data_/img_Calque-1.gif" alt="" name="img_Calque_1" height="66" width="162" border="0" livesrc="images/registration_button.psd"></a><input type="submit" name="submitButtonName"></div>
    									</td>
    								</tr>
    							</table>
    						</td>
    					</tr>
    				</table>
    			</form>
    		</div>
    	</body>
     
    </html>


    Et voici le code de la page register.php
    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
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
     
    	<head>
    		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    		<meta name="generator" content="Adobe GoLive">
    		<title>Thank you for your registration</title>
    	</head>
     
    	<body bgcolor="#ffffff">
    		<?php
     
    if (empty($_post['activities']) || empty($_post['society']) || empty($_post['adress1']) || 
        empty($_post['adresse2']) || empty($_post['country']) || empty($_post['email']) || 
        empty($_post['web']) || empty($_post['password']))
     
    die ("ERROR : Please, fill out every field.");
     
     
    if (preg_match("/^[\w\.-]+@[\w\.-]+\.[a-z]{2,3}$/",
    $_REQUEST ['email']) ==  false)
     
     
    die("ERREUR : adresse email non valide.");
     
    // connection base de donnée
     
    	$liendb = mysql_connect ('localhost', 'wootchs', 'HamadA');
    	mysql_select_db ("members", $liendb);
    	$sql = "INSERT INTO 'registred' ('activities', 'society', 'adress1', 'adress2', 'country', 'email', 'web', 'password', 'id')	VALUES ($_POST['activities'], $_POST['society'], $_POST['adress1'], $_POST['adress2'], $_POST['country'], $_POST['email'], $_POST['web'], $_POST['password'], $_POST[''])";
     
    // fin requete base de donnée
     
     
    	if ($result = mysql_query($sql) !=false)    
        print("user".$_REQUEST['name']." registred.");
     
    	else 
        print ("Error during registration.");
     
    	mysql_close($liendb);
     
    		?>
     
    	</body>
     
    </html>

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations forums :
    Inscription : Mars 2004
    Messages : 124
    Points : 95
    Points
    95
    Par défaut
    Salut,

    Pourquoi mets-tu
    à la fin de ta requête SQL
    Mieux vaut rien dire que de se taire !

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mars 2008
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    salut Sun3clipse et merci pour ta réponse,

    Je suis un pur débutant en php/mysql. Le " ne doit-il pas refermer celui se trouvant devant INSERT INTO ?

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Août 2006
    Messages
    199
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 199
    Points : 116
    Points
    116
    Par défaut
    $sql = "INSERT INTO 'registred' ('activities', 'society', 'adress1', 'adress2', 'country', 'email', 'web', 'password', 'id') VALUES ($_POST['activities'], $_POST['society'], $_POST['adress1'], $_POST['adress2'], $_POST['country'], $_POST['email'], $_POST['web'], $_POST['password'], $_POST[''])";
    Je ne crois pas que le nom de la table ainsi que ceux des champs nécessitent d'être entre apostrophes mais par contre les nouvelle valeurs entrées c'est bien possible. Tu as essayé ça?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $sql = "INSERT INTO registred (activities, society, adress1, adress2, country, email, web, password, id)	VALUES ('$_POST['activities']', '$_POST['society']', '$_POST['adress1']', '$_POST['adress2']', '$_POST['country']', '$_POST['email']', '$_POST['web']', '$_POST['password']', '$_POST['']')";
    voire ça qui me semblerait plus clair à la relecture du code (enfin tout dépend aussi de la coloration syntaxique de ton éditeur...)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $sql = "INSERT INTO registred (activities, society, adress1, adress2, country, email, web, password, id)	VALUES ('".$_POST['activities']."', '".$_POST['society']."', '".$_POST['adress1']."', '".$_POST['adress2']."', '".$_POST['country']."', '".$_POST['email']."', '".$_POST['web']."', '".$_POST['password']."', '".$_POST['']."')";

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mars 2008
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    Salut f56bre,

    Alors là tu assures !! J'ai enlevé les ' au nom de la table et j'ai ajouté '". aux nouvelles valeurs et ça fonctionne.

    Maintenant je vais pouvoir mettre en place les tests conditionnels comme pour les champs vides, etc..

    Merci beaucoup à vous deux, a+.

    Ossie

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 18/04/2008, 15h12
  2. Réponses: 1
    Dernier message: 16/04/2008, 06h42
  3. Réponses: 4
    Dernier message: 24/08/2006, 13h13
  4. Evenement sur nouvel enregistrement dans formulaire
    Par fredoh dans le forum Access
    Réponses: 3
    Dernier message: 17/07/2006, 14h19
  5. Positionnement sur un enregistrement dans un formulaire
    Par bestall666 dans le forum Access
    Réponses: 5
    Dernier message: 04/02/2006, 17h10

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