$_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   -
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

15 réponses

Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
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 :
$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
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
Bonjour et merci xavier j'ai fait les modifs mais je n'ai toujours rien qui s'inscrit en base.
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
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
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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', '', '', '', '', '', '' )
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
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
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
Laisse tomber ce message, c'est une c***rie :p
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
ps: DURAND et PIERRE sont des données saisie dans mon formulaire
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
Ça c'est parce que dans ta dernière requête tu t'es mélangé dans les guillemets
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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"]}"



)";
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
$req_bailleur="INSERT
[...]
VALUES ("{$_

ce " ferme la chaîne initiée plus haut.
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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"]}"



)";
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
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 ?
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
dans phpmyadmin ce les double cote
0
Reivax962 Messages postés 3672 Date d'inscription   Statut Membre Dernière intervention   1 011
 
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']}' 

)"; 
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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', '', '', '', '', '', '' )
0
maka54 Messages postés 698 Date d'inscription   Statut Membre Dernière intervention   80
 
$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']."'

)";
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
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', '', '', '', '', '', '' )
0
techinfo46 Messages postés 383 Date d'inscription   Statut Membre Dernière intervention   56
 
oooo je suis désolé..j'ai trop honte la...

VILLEBAILLEUR_1 et orthographier dans ma table VILLEBAILEUR_1

voila la raison... si non le dernier script de maka54 fonctionne ainsi que le dernier script de Reivax962*


merci à vous deux
0