$_SESSION et MYSQL
Résolu
techinfo46
Messages postés
383
Date d'inscription
Statut
Membre
Dernière intervention
-
techinfo46 Messages postés 383 Date d'inscription Statut Membre Dernière intervention -
techinfo46 Messages postés 383 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai un souci, quand je rentre le code suivant, les valeurs ne vont pas s'inscrire dans la base.
<?php
session_start();
include('connection.php');
echo $_SESSION['BAILLEURPHYSIQUE'][1]['prenombailleur'];
if ($_SESSION['TYPEBAILLEUR'] == 'OUI') {
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1',
'PRENOMBAILLEUR_1',
'ADRESSEBAILLEUR_1',
'TELBAILLEUR_1',
'FAXBAILLEUR_1',
'VILLEBAILLEUR_1',
'CODEPOSTALBAILLEUR_1',
'MAILBAILLEUR_1'
)
VALUES ('$_SESSION[BAILLEURPHYSIQUE][1][nombailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][prenombailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][adressebailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][telbailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][faxbailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][villebailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][codepostalbailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][mailbailleur]'
)";
$result = mysql_query($req_bailleur);
};
?>
L'écho affiche bien la valeur voulu.
merci d'avance
J'ai un souci, quand je rentre le code suivant, les valeurs ne vont pas s'inscrire dans la base.
<?php
session_start();
include('connection.php');
echo $_SESSION['BAILLEURPHYSIQUE'][1]['prenombailleur'];
if ($_SESSION['TYPEBAILLEUR'] == 'OUI') {
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1',
'PRENOMBAILLEUR_1',
'ADRESSEBAILLEUR_1',
'TELBAILLEUR_1',
'FAXBAILLEUR_1',
'VILLEBAILLEUR_1',
'CODEPOSTALBAILLEUR_1',
'MAILBAILLEUR_1'
)
VALUES ('$_SESSION[BAILLEURPHYSIQUE][1][nombailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][prenombailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][adressebailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][telbailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][faxbailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][villebailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][codepostalbailleur]',
'$_SESSION[BAILLEURPHYSIQUE][1][mailbailleur]'
)";
$result = mysql_query($req_bailleur);
};
?>
L'écho affiche bien la valeur voulu.
merci d'avance
A voir également:
- $_SESSION et MYSQL
- Mysql community server - Télécharger - Bases de données
- Mysql gratuit ou payant - Forum MySQL
- Could not connect to mysql! please check your database settings! - Forum Redhat
- Mysql error 1 ✓ - Forum Réseaux sociaux
- Access vs mysql - Forum Webmastering
15 réponses
Bonjour,
Le problème vient du fait que les tableaux ne sont pas interprétés dans les chaînes PHP.
Il a dû te mettre un message d'erreur...
La solution est soit de découper la chaîne en morceaux et de les concaténer (opérateur « . ») soit d'utiliser des accolades.
Autre chose, dans ton « echo » tu mets bien des apostrophes droites autour des noms des champs du tableau, mais pas dans ta requête...
Ce qui donne :
Xavier
Le problème vient du fait que les tableaux ne sont pas interprétés dans les chaînes PHP.
Il a dû te mettre un message d'erreur...
La solution est soit de découper la chaîne en morceaux et de les concaténer (opérateur « . ») soit d'utiliser des accolades.
Autre chose, dans ton « echo » tu mets bien des apostrophes droites autour des noms des champs du tableau, mais pas dans ta requête...
Ce qui donne :
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1', 'PRENOMBAILLEUR_1', 'ADRESSEBAILLEUR_1', 'TELBAILLEUR_1', 'FAXBAILLEUR_1', 'VILLEBAILLEUR_1', 'CODEPOSTALBAILLEUR_1', 'MAILBAILLEUR_1' ) VALUES ('{$_SESSION['BAILLEURPHYSIQUE'][1]['nombailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['prenombailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['adressebailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['telbailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['faxbailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['villebailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['codepostalbailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['mailbailleur']}' )";
Xavier
Bon, alors remplace ça
$result = mysql_query($req_bailleur);
par ça :
echo $req_bailleur."<br />";
$result = mysql_query($req_bailleur) or die (mysql_error()."<br />$req_bailleur");
Relance, et dis-nous quel est le message d'erreur qui s'affiche.
Fais aussi un
echo $_SESSION['TYPEBAILLEUR']
Pour être sûr qu'il contienne bien 'OUI'...
Xavier
$result = mysql_query($req_bailleur);
par ça :
echo $req_bailleur."<br />";
$result = mysql_query($req_bailleur) or die (mysql_error()."<br />$req_bailleur");
Relance, et dis-nous quel est le message d'erreur qui s'affiche.
Fais aussi un
echo $_SESSION['TYPEBAILLEUR']
Pour être sûr qu'il contienne bien 'OUI'...
Xavier
bonjour xavier et merci de ton soutien voici le message d'erreur
Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in C:\Program Files (x86)\EasyPHP-5.3.8.0\www\test7.php on line 6
par contre effectivement mon echo $_SESSION['TYPEBAILLEUR'] n'affiche rien
Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in C:\Program Files (x86)\EasyPHP-5.3.8.0\www\test7.php on line 6
par contre effectivement mon echo $_SESSION['TYPEBAILLEUR'] n'affiche rien
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
re xavier, pour l'echo avais oublier de mettre le point virgule donc du cout voici le message d'erreur:
OUIINSERT INTO bailleur ('NOMBAILLEUR_1', 'PRENOMBAILLEUR_1', 'ADRESSEBAILLEUR_1', 'TELBAILLEUR_1', 'FAXBAILLEUR_1', 'VILLEBAILLEUR_1', 'CODEPOSTALBAILLEUR_1', 'MAILBAILLEUR_1' ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Champ 'DURAND' inconnu dans field list
INSERT INTO bailleur ('NOMBAILLEUR_1', 'PRENOMBAILLEUR_1', 'ADRESSEBAILLEUR_1', 'TELBAILLEUR_1', 'FAXBAILLEUR_1', 'VILLEBAILLEUR_1', 'CODEPOSTALBAILLEUR_1', 'MAILBAILLEUR_1' ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
OUIINSERT INTO bailleur ('NOMBAILLEUR_1', 'PRENOMBAILLEUR_1', 'ADRESSEBAILLEUR_1', 'TELBAILLEUR_1', 'FAXBAILLEUR_1', 'VILLEBAILLEUR_1', 'CODEPOSTALBAILLEUR_1', 'MAILBAILLEUR_1' ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Champ 'DURAND' inconnu dans field list
INSERT INTO bailleur ('NOMBAILLEUR_1', 'PRENOMBAILLEUR_1', 'ADRESSEBAILLEUR_1', 'TELBAILLEUR_1', 'FAXBAILLEUR_1', 'VILLEBAILLEUR_1', 'CODEPOSTALBAILLEUR_1', 'MAILBAILLEUR_1' ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Bonjour,
« Champ 'DURAND' inconnu dans field list »
Ah...
Apparemment, ton champ NOMBAILLEUR_1 est défini comme ne pouvant contenir qu'une liste prédéfinie de noms : tu ne peux pas y mettre n'importe quelle chaîne de caractère.
Je pense qu'il y a un soucis dans la définition de ta table bailleur.
Tu peux en donner le script de création ?
(SHOW CREATE TABLE bailleur, de mémoire, en SQL)
Xavier
« Champ 'DURAND' inconnu dans field list »
Ah...
Apparemment, ton champ NOMBAILLEUR_1 est défini comme ne pouvant contenir qu'une liste prédéfinie de noms : tu ne peux pas y mettre n'importe quelle chaîne de caractère.
Je pense qu'il y a un soucis dans la définition de ta table bailleur.
Tu peux en donner le script de création ?
(SHOW CREATE TABLE bailleur, de mémoire, en SQL)
Xavier
re xavier
j'ai passer ma requette sur phpmyadmin et voici le résultat
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1',
'PRENOMBAILLEUR_1',
'ADRESSEBAILLEUR_1',
'TELBAILLEUR_1',
'FAXBAILLEUR_1',
'VILLEBAILLEUR_1',
'CODEPOSTALBAILLEUR_1',
'MAILBAILLEUR_1'
)
VALUES ("{$_SESSION["BAILLEURPHYSIQUE"][1]["nombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["prenombailleur"]}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['adressebailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['telbailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['faxbailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['villebailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['codepostalbailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['mailbailleur']}"
)";
la requette fonctionne bien dans phpmyadmin
mais maintenant voici le message d'erreur qui s'affiche:
Parse error: syntax error, unexpected '{' in C:\Program Files (x86)\EasyPHP-5.3.8.0\www\test7.php on line 22
j'ai passer ma requette sur phpmyadmin et voici le résultat
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1',
'PRENOMBAILLEUR_1',
'ADRESSEBAILLEUR_1',
'TELBAILLEUR_1',
'FAXBAILLEUR_1',
'VILLEBAILLEUR_1',
'CODEPOSTALBAILLEUR_1',
'MAILBAILLEUR_1'
)
VALUES ("{$_SESSION["BAILLEURPHYSIQUE"][1]["nombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["prenombailleur"]}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['adressebailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['telbailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['faxbailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['villebailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['codepostalbailleur']}",
"{$_SESSION['BAILLEURPHYSIQUE'][1]['mailbailleur']}"
)";
la requette fonctionne bien dans phpmyadmin
mais maintenant voici le message d'erreur qui s'affiche:
Parse error: syntax error, unexpected '{' in C:\Program Files (x86)\EasyPHP-5.3.8.0\www\test7.php on line 22
je ne voie pas le souci:
VALUES ("{$_SESSION["BAILLEURPHYSIQUE"][1]["nombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["prenombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["adressebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["telbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["faxbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["villebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["codepostalbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["mailbailleur"]}"
)";
VALUES ("{$_SESSION["BAILLEURPHYSIQUE"][1]["nombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["prenombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["adressebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["telbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["faxbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["villebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["codepostalbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["mailbailleur"]}"
)";
la modif que tu me demande de faire et deja présente
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1',
'PRENOMBAILLEUR_1',
'ADRESSEBAILLEUR_1',
'TELBAILLEUR_1',
'FAXBAILLEUR_1',
'VILLEBAILLEUR_1',
'CODEPOSTALBAILLEUR_1',
'MAILBAILLEUR_1'
)
VALUES("{$_SESSION["BAILLEURPHYSIQUE"][1]["nombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["prenombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["adressebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["telbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["faxbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["villebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["codepostalbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["mailbailleur"]}"
)";
$req_bailleur="INSERT INTO bailleur ('NOMBAILLEUR_1',
'PRENOMBAILLEUR_1',
'ADRESSEBAILLEUR_1',
'TELBAILLEUR_1',
'FAXBAILLEUR_1',
'VILLEBAILLEUR_1',
'CODEPOSTALBAILLEUR_1',
'MAILBAILLEUR_1'
)
VALUES("{$_SESSION["BAILLEURPHYSIQUE"][1]["nombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["prenombailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["adressebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["telbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["faxbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["villebailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["codepostalbailleur"]}",
"{$_SESSION["BAILLEURPHYSIQUE"][1]["mailbailleur"]}"
)";
Oh attend, une idée comme ça...
Quelles apostrophes tu utilises autour de 'DURAND' ? Celles qui sont sous le 4 ou celles qui sont sous le 7 ?
Quelles apostrophes tu utilises autour de 'DURAND' ? Celles qui sont sous le 4 ou celles qui sont sous le 7 ?
Au niveau de ton php, essaie de copier-coller ce code-là :
$req_bailleur = "INSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('{$_SESSION['BAILLEURPHYSIQUE'][1]['nombailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['prenombailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['adressebailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['telbailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['faxbailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['villebailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['codepostalbailleur']}', '{$_SESSION['BAILLEURPHYSIQUE'][1]['mailbailleur']}' )";
voici le message que j'ai quand je fait un copie coller de ton code:
OUIINSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Champ 'VILLEBAILLEUR_1' inconnu dans field list
INSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
OUIINSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Champ 'VILLEBAILLEUR_1' inconnu dans field list
INSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
$req_bailleur = "INSERT INTO bailleur (NOMBAILLEUR_1,
PRENOMBAILLEUR_1,
ADRESSEBAILLEUR_1,
TELBAILLEUR_1,
FAXBAILLEUR_1,
VILLEBAILLEUR_1,
CODEPOSTALBAILLEUR_1,
MAILBAILLEUR_1
)
VALUES ('".$_SESSION['BAILLEURPHYSIQUE'][1]['nombailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['prenombailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['adressebailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['telbailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['faxbailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['villebailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['codepostalbailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['mailbailleur']."'
)";
PRENOMBAILLEUR_1,
ADRESSEBAILLEUR_1,
TELBAILLEUR_1,
FAXBAILLEUR_1,
VILLEBAILLEUR_1,
CODEPOSTALBAILLEUR_1,
MAILBAILLEUR_1
)
VALUES ('".$_SESSION['BAILLEURPHYSIQUE'][1]['nombailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['prenombailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['adressebailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['telbailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['faxbailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['villebailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['codepostalbailleur']."',
'".$_SESSION['BAILLEURPHYSIQUE'][1]['mailbailleur']."'
)";
Bonjour maka voici ce qui mes afficher:
OUIINSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Champ 'VILLEBAILLEUR_1' inconnu dans field list
INSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
OUIINSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )
Champ 'VILLEBAILLEUR_1' inconnu dans field list
INSERT INTO bailleur (NOMBAILLEUR_1, PRENOMBAILLEUR_1, ADRESSEBAILLEUR_1, TELBAILLEUR_1, FAXBAILLEUR_1, VILLEBAILLEUR_1, CODEPOSTALBAILLEUR_1, MAILBAILLEUR_1 ) VALUES ('DURAND', 'PIERRE', '', '', '', '', '', '' )