Précédent   Forum des professionnels en informatique > PHP > Langage > Syntaxe
Syntaxe Forum d'entraide sur la syntaxe de PHP et la POO. Avant de poster -> FAQ syntaxe, Cours d'initiation et cours de POO
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 07/06/2011, 09h22   #1
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
Par défaut Récupération de la valeur d'un champ

mon code réalise une liste déroulante, avec des nom a l'intérieur et quand je clique sur un nom, que j'appuie sur le boutton ok; j'aimerai qui me renvoi le nom suivi du codeinfo.. si quelqu'un voudrait bien m'aider je lui en serait reconnaissant
Code :
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
 $config=array(
  'Database'=>'udaf34',
  'UID'=>'sa',
  'PWD'=>'admin13@');
$idconnect=sqlsrv_connect('(local)',$config);
    if( $idconnect === false )
{
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));
}
$result=sqlsrv_query($idconnect,'SELECT codeinfo,nom FROM clientordon order by nom asc ');
 
 
echo '<form name="selection" action="proto_php_sqlserver.php" method="post">
<select name="liste_deroulante">';
while($nini=sqlsrv_fetch_array($result))
{
    echo '<option value="' . $nini['nom'] . '">' . htmlentities($nini['nom']) . '</option>';
}
echo '</select>
<input type="submit" value="OK">
</form>';
 
while($nini=sqlsrv_fetch_array($result))
{
  echo '<option value='. $nini['nom']}-{$nini['codeinfo']}">" . htmlentities($nini['nom']) . '</option>';
}
 
if (isset($_POST['liste_deroulante']))
{
  list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante']) + array("");
}
 
?>
merci développeur
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 09h32   #2
Membre Expert
 
Avatar de Bebel
 
Homme David B.
Développeur informatique
Inscription : avril 2003
Messages : 742
Détails du profil
Informations personnelles :
Nom : Homme David B.
Âge : 29
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Développeur informatique
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2003
Messages : 742
Points : 1 085
Points : 1 085
Bonjour,

dans ton code
Code :
echo '<option value="' . $nini['nom'] . '">' . htmlentities($nini['nom']) . '</option>';
il suffit de remplacer le premier $nini['nom'] par $nini['codeinfo'].

ce qu'il y a dans l'attribut value est la valeur envoyée par la validation.
Ce qu'il y a entre les balises <option> correspond à la valeur affichée dans le formulaire.
__________________
Tout énigme a une solution ! Tout est question de discipline !
Bebel est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 09h38   #3
Membre éclairé
 
Homme Jérémy
Étudiant
Inscription : octobre 2009
Messages : 236
Détails du profil
Informations personnelles :
Nom : Homme Jérémy
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Produits et services télécom et Internet

Informations forums :
Inscription : octobre 2009
Messages : 236
Points : 322
Points : 322
Code :
1
2
3
4
while($nini=sqlsrv_fetch_array($result))
{
  echo '<option value='. $nini['nom']}-{$nini['codeinfo']}">" . htmlentities($nini['nom']) . '</option>';
}
Code :
1
2
3
4
while($nini=sqlsrv_fetch_array($result))
{
  echo '<option value='. $nini['nom'].'-'.$nini['codeinfo'].">" . htmlentities($nini['nom']) . '</option>';
}
gwharl est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 09h42   #4
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
Par défaut tjrs erreur..

j'ai suivi t'es conseille mais on me dit que j'ai toujours une erreur partiel dans ce secteur.. jtrouve pas
Code :
1
2
3
4
5
 
while($nini=sqlsrv_fetch_array($result))
{
  echo '<option value="'. {$nini['nom']}-{$nini['codeinfo']}'">"' . htmlentities($nini['nom']) . '"</option>';
}
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 09h50   #5
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
sa se connecte mais quand je clique sur un nom de ma liste déroulante sa ne me renvoi pas les codeinfo sa renvoi:

Notice: Undefined offset: 1 in C:\wamp\www\php_proto\proto_php_sqlserver.php on line 34

avec ma liste déroulante qui précedent ce message.
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 09h55   #6
Membre habitué
 
Avatar de Chen norris
 
Inscription : mai 2004
Messages : 124
Détails du profil
Informations personnelles :
Âge : 27
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : mai 2004
Messages : 124
Points : 101
Points : 101
Bonjour,

Ton erreur indique que tu cherches à accéder à un élément de tableau à un indice qui n'existe pas. Au vu de ta requête, $nini['nom'] et $nini['codeinfo'] semblent OK.

Qu'y a-t-il à la ligne 34 de ton code ?
__________________
Chen norris
C/C++, C#, Java, PHP & SQL coder
Web developer
Chen norris est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 09h59   #7
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
bonjour chen norris voila ma ligne 34 en espérant que l'erreur te parle
Code :
1
2
 
 list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante']) + array("");
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 10h09   #8
Membre éclairé
 
Homme Jérémy
Étudiant
Inscription : octobre 2009
Messages : 236
Détails du profil
Informations personnelles :
Nom : Homme Jérémy
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Produits et services télécom et Internet

Informations forums :
Inscription : octobre 2009
Messages : 236
Points : 322
Points : 322
Etrange, cette structure marche :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
	echo '<form name="selection" action="index.php" method="post">
 
		<select name="liste_deroulante">';
			echo '<option value="nom-code">1</option>';
		echo '</select>
 
		<input type="submit" value="OK">
	</form>';
 
	if (isset($_POST['liste_deroulante']))
	{
		list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante']) + array("");
	}
 
	echo $nom.' '.$codeinfo;
?>
Test juste avant un
Code :
print_r($_POST['liste_deroulante'])
gwharl est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 10h20   #9
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
Par défaut me revoila

revoila mon code aprés quelque modifications apporté par vos connaissances:
Code :
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
 
<?php
 $config=array(
  'Database'=>'udaf34',
  'UID'=>'sa',
  'PWD'=>'admin13@');
$idconnect=sqlsrv_connect('(local)',$config);
    if( $idconnect === false )
{
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));
}
$result=sqlsrv_query($idconnect,'SELECT codeinfo,nom FROM clientordon order by nom asc ');
 
 
echo '<form name="selection" action="proto_php_sqlserver.php" method="post">
<select name="liste_deroulante">';
while($nini=sqlsrv_fetch_array($result))
{
    echo '<option value="' . $nini['codeinfo'] . '">' . htmlentities($nini['nom']) . '</option>';
}
echo '</select>
<input type="submit" value="OK">
</form>';
 
while($nini=sqlsrv_fetch_array($result))
{
  echo '<option value='. $nini['nom'].'-'.$nini['codeinfo'].">" . htmlentities($nini['nom']);
}
 
 
if (isset($_POST['liste_deroulante']))
{
  list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante']);
}
echo $nom.' '.$codeinfo;
 
?>
mais maintenant cela me dit:

Notice: Undefined variable: nom in C:\wamp\www\php_proto\proto_php_sqlserver.php on line 36

Notice: Undefined variable: codeinfo in C:\wamp\www\php_proto\proto_php_sqlserver.php on line 36
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 10h22   #10
Membre éclairé
 
Homme Jérémy
Étudiant
Inscription : octobre 2009
Messages : 236
Détails du profil
Informations personnelles :
Nom : Homme Jérémy
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Produits et services télécom et Internet

Informations forums :
Inscription : octobre 2009
Messages : 236
Points : 322
Points : 322
Cela signifie que ton code ne rentre pas dans le if
Code :
1
2
3
4
if (isset($_POST['liste_deroulante']))
{
  list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante']);
}
Donc ton $_POST['liste_deroulante'] est vide.
gwharl est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 07/06/2011, 10h25   #11
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
comment faire alors ac se code
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/06/2011, 11h11   #12
Invité de passage
 
Homme joris
Étudiant
Inscription : juin 2011
Messages : 36
Détails du profil
Informations personnelles :
Nom : Homme joris
Localisation : France, Hérault (Languedoc Roussillon)

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Matériel informatique

Informations forums :
Inscription : juin 2011
Messages : 36
Points : 1
Points : 1
Code :
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
 $config=array(
  'Database'=>'*****',
  'UID'=>'**',
  'PWD'=>'*****');
$idconnect=sqlsrv_connect('(local)',$config);
    if( $idconnect === false )
{
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));
}
$result=sqlsrv_query($idconnect,'SELECT codeinfo,nom FROM Tclientordon order by nom asc ');
 
 
echo '<form name="selection" action="proto_php_sqlserver.php" method="post">
<select name="liste_deroulante">';
while($nini=sqlsrv_fetch_array($result))
{
    echo '<option value="' . $nini['codeinfo'] . '">' . htmlentities($nini['nom']) . '</option>';
}
echo '</select>
<input type="submit" value="OK">
</form>';
 
while($nini=sqlsrv_fetch_array($result))
{
  echo '<option value='. $nini['nom']}.'-'.{$nini['codeinfo']}.">" . htmlentities($nini['nom']) . '</option>';  //probleme sur cette ligne 
}
 if (isset($_POST['liste_deroulante']))
{
  list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante'])
}
 
?>
djolah13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/06/2011, 10h27   #13
Membre habitué
 
Avatar de Chen norris
 
Inscription : mai 2004
Messages : 124
Détails du profil
Informations personnelles :
Âge : 27
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : mai 2004
Messages : 124
Points : 101
Points : 101
Bonjour,

N'affiche $nom et $codeinfo que si tu rentres dans le if sinon, tu risques d'afficher des variables non initialisées :

Code :
1
2
3
4
5
if (isset($_POST['liste_deroulante']))
{
  list($nom, $codeinfo) = explode('-', $_POST['liste_deroulante']);
  echo $nom.' '.$codeinfo;
}
Pour ce qui est de la ligne avec problème, je ne connais pas la syntaxe avec accolades qui me semble pour le moins curieuse. Que souhaites-tu afficher ? Est-ce que tu ne cherches pas plutôt à faire ça ? ->

Code :
1
2
 
echo "<option value=\"".$nini["nom"]."-".$nini["codeinfo"]."\">".htmlentities($nini["nom"])."</option>";
note : j'ai ajouté des guillemets pour la valeur des options, ça t'évitera du code HTML pas très standard.
__________________
Chen norris
C/C++, C#, Java, PHP & SQL coder
Web developer
Chen norris est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 20h25.


 
 
 
 
Partenaires

Hébergement Web