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 12/09/2007, 13h57   #1
Membre confirmé
 
Inscription : mars 2003
Messages : 674
Détails du profil
Informations forums :
Inscription : mars 2003
Messages : 674
Points : 242
Points : 242
Par défaut Variable non définie

Bonjour.

Quand je veux enregistrer des modifications dans une tables j'ai un message qui m'annonce :'Undefinded variable langue ... line 142,
Undefined variable langue_sst ... line 158'

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
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
function est_selectionne_langue($option) {
    if (!isset($_POST['langue'])) {
            return FALSE;
    }
    for ($i = 0, $c = count($_POST['langue']); $i < $c; $i++) {
        if ($_POST['langue'][$i] == $option) {
            return TRUE;
        }
    }
    return FALSE;
}
...
function est_selectionne_langue_sst($option) {
    if (!isset($_POST['langue_sst'])) {
            return FALSE;
    }
    for ($i = 0, $c = count($_POST['langue_sst']); $i < $c; $i++) {
        if ($_POST['langue_sst'][$i] == $option) {
            return TRUE;
        }
    }
    return FALSE;
}
...
if (isset($_POST['langue'])) {
    for ($i = 0, $c = count($_POST['langue']); $i < $c; $i++) {
	$langue .=  "" . $_POST['langue'][$i] . ",";   ***line 142***
    }
	$langue= substr($langue,0,strlen($langue)-1);
}
else {
	$langue="";
}
...
if (isset($_POST['langue_sst'])) {
    for ($i = 0, $c = count($_POST['langue_sst']); $i < $c; $i++) {
        $langue_sst .= "" . $_POST['langue_sst'][$i] . ",";  ***line 158***
    }
	$langue_sst= substr($langue_sst,0,strlen($langue_sst)-1);
}
...
	$sql = mysql_query("SELECT * FROM version_dvd wHERE id_titre = $choix AND id = $iddvd");
	if (mysql_num_rows($sql) > 0){
	   	$res = mysql_fetch_array($sql);
	   	$id = $res['id'];
	   	$langue = $res['langue'];
	   	$sous_titre = $res['sous_titre'];
	   	$langue_sst = $res['langue_sous_titre'];
	   	$public = $res['public'];

		$langue = explode(",",$langue);
		$langue_sst = explode(",",$langue_sst);
	}
			<p align="center">Langue<hr width='100px'>
    			<input type="checkbox" name="langue[]" value="Français" <?php if(est_selectionne_langue("Français")) { echo 'checked'; } else if(!empty($langue)){ if(in_array("Français",$langue)) { echo 'checked'; }} ?>/>Français<br/>
    			<input type="checkbox" name="langue[]" value="Anglais" <?php if(est_selectionne_langue("Anglais")) { echo 'checked'; } else if(!empty($langue)){ if(in_array("Anglais",$langue)) { echo 'checked'; }} ?>/>Anglais<br/>
    			<input type="checkbox" name="langue[]" value="Italien" <?php if(est_selectionne_langue("Italien")) { echo 'checked'; } else if(!empty($langue)){ if(in_array("Italien",$langue)) { echo 'checked'; }} ?>/>Italien<br/>
    			<input type="checkbox" name="langue[]" value="Allemand" <?php if(est_selectionne_langue("Allemand")) { echo 'checked'; } else if(!empty($langue)){ if(in_array("Allemand",$langue)) { echo 'checked'; }} ?>/>Allemand<br/>
    			<input type="checkbox" name="langue[]" value="Espagnol" <?php if(est_selectionne_langue("Espagnol")) { echo 'checked'; } else if(!empty($langue)){ if(in_array("Espagnol",$langue)) { echo 'checked'; }} ?>/>Espagnol<br/>
    			<input type="checkbox" name="langue[]" value="Portugais" <?php if(est_selectionne_langue("Portugais")) { echo 'checked'; } else if(!empty($langue)){ if(in_array("Portugais",$langue)) { echo 'checked'; }} ?>/>Portugais<br/>
			</p>
    			<input type="checkbox" name="langue_sst[]" value="Français" <?php if(est_selectionne_langue_sst("Français")) { echo 'checked'; } else if(!empty($langue_sst)){ if(in_array("Français",$langue_sst)) { echo 'checked'; }} ?>/>Français<br/>
    			<input type="checkbox" name="langue_sst[]" value="Anglais" <?php  if(est_selectionne_langue_sst("Anglais")) { echo 'checked'; } else if(!empty($langue_sst)){ if(in_array("Anglais",$langue_sst)) { echo 'checked'; }} ?>/>Anglais<br/>
    			<input type="checkbox" name="langue_sst[]" value="Italien" <?php  if(est_selectionne_langue_sst("Italien")) { echo 'checked'; } else if(!empty($langue_sst)){ if(in_array("Italien",$langue_sst)) { echo 'checked'; }} ?>/>Italien<br/>
    			<input type="checkbox" name="langue_sst[]" value="Allemand" <?php if(est_selectionne_langue_sst("Allemand")) { echo 'checked'; } else if(!empty($langue_sst)){ if(in_array("Allemand",$langue_sst)) { echo 'checked'; }} ?>/>Allemand<br/>
    			<input type="checkbox" name="langue_sst[]" value="Espagnol" <?php if(est_selectionne_langue_sst("Espagnol")) { echo 'checked'; } else if(!empty($langue_sst)){ if(in_array("Espagnol",$langue_sst)) { echo 'checked'; }} ?>/>Espagnol<br/>
    			<input type="checkbox" name="langue_sst[]" value="Portugais" <?php if(est_selectionne_langue_sst("Portugais")) { echo 'checked'; } else if(!empty($langue_sst)){ if(in_array("Portugais",$langue_sst)) { echo 'checked'; }} ?>/>Portugais<br/>
    			</p>
Sur cette page j'ai des boutons radio et des checkbox, ça marche pour les boutons radio mais pas pour les checkbox.

Merci de me dire ce qui ne va pas.
philippef est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/09/2007, 14h34   #2
Invité de passage
 
Inscription : juin 2007
Messages : 5
Détails du profil
Informations forums :
Inscription : juin 2007
Messages : 5
Points : 2
Points : 2
C'est tout bete ..

c'est simplement parceque tu déclare ta variable des le debut en la concaténant

Code :
1
2
3
4
5
6
7
8
9
10
 
if (isset($_POST['langue'])) {
    for ($i = 0, $c = count($_POST['langue']); $i < $c; $i++) {
	$langue .=  "" . $_POST['langue'][$i] . ",";   ***line 142***
    }
	$langue= substr($langue,0,strlen($langue)-1);
}
else {
	$langue="";
}
devrait etre
Code :
1
2
3
4
5
6
7
8
 
$langue ='';
if (isset($_POST['langue'])) {
    for ($i = 0, $c = count($_POST['langue']); $i < $c; $i++) {
	$langue .=  "" . $_POST['langue'][$i] . ",";   ***line 142***
    }
	$langue= substr($langue,0,strlen($langue)-1);
}
tu dois d'abord déclarer ta variable avant de la concaténer

ne pas oublier que que
$langue .=

revient à écrire
$langue = $langue.$var;


PeterPetrelli 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 05h15.


 
 
 
 
Partenaires

Hébergement Web