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

PHP & Base de données Discussion :

Update SQL qui ne trouve pas mes variables


Sujet :

PHP & Base de données

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 29
    Points : 12
    Points
    12
    Par défaut Update SQL qui ne trouve pas mes variables
    Bonjour,

    Je suis en train d'essayer de faire un site pour mon club de foot avec match, classement ..., je bloque sur la mise à jour des matchs.

    J'ai un tableau avec mes matchs, au bout de la ligne, un bouton modifier qui me redirige vers un 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
    <fieldset>
    					<legend>Mise à jour d'un match</legend>
    				<table>
    <?php
        $req = $bdd->prepare('
    	SELECT match.id AS `match_id`, journee, DATE_FORMAT(date, \'%d/%m/%Y\') AS date, dom.nom AS `dom_nom`, ext.nom AS `ext_nom`,  buts_dom, buts_ext, statut.statut AS `statut_nom`
    	FROM `match`, `equipe` AS dom, `equipe` AS ext, `match_statut` AS statut
    	WHERE id_equipe_dom=dom.id 
    	AND id_equipe_ext=ext.id 
    	AND match.id=\'' . $_GET['match_id'] . '\'
    	GROUP BY match.id
    	');
        $req->execute(array($_GET['match_id']));
    	while ($donnees = $req->fetch())
    	{
    ?>
    				<form action="update_match.php" method="post">
    				<tr>
    					<td>
    						<label for="match_id">ID du match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["match_id"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="journee">Journée</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["journee"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="date">Date</label> : 
    					</td>
    					<td>
    						<input type="text" name="date" id="date" size="10" value="<?php echo ''.$donnees["date"].' ';?>"/>  (exemple 31/07/2011)
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="dom_nom">Match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["dom_nom"].' ';?> - <?php echo ''.$donnees["ext_nom"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="buts_dom">Score</label> : 
    					</td>
    					<td>
    						<input type="text" name="buts_dom" id="buts_dom" size="3" value="<?php echo ''.$donnees["buts_dom"].' ';?>"/> - <input type="text" name="buts_ext" id="buts_ext" size="3" value="<?php echo ''.$donnees["buts_ext"].' ';?>"/>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="statut_nom">Statut</label> : 
    					</td>
    					<td>
    						<select name="statut_nom" id="id_match_statut" value="<?php echo ''.$donnees["statut_nom"].' ';?>"/>
    					<option value="1" <?php if ($donnees["statut_nom"] == "1") {echo("selected");}?> >Match à jouer</option>
    					<option value="2" <?php if ($donnees["statut_nom"] == "2") {echo("selected");}?> >Match joué</option>
    					<option value="3" <?php if ($donnees["statut_nom"] == "3") {echo("selected");}?> >Forfait domicile</option>
    					<option value="4" <?php if ($donnees["statut_nom"] == "4") {echo("selected");}?> >Forfait exterieur</option></select>
    					</td>
    				</tr>
    				<tr>
    				<td>
                    	<a href="admin_match.php"><img src="../images/retour.png" alt="Retour" title="Retour" /></a>
    				</td>
    				<td>
    					<input type="submit" value="Mettre à jour"/>
    				</td>
    <?php
    //On ferme la boucle while
     }
    ?>
    				</table>
    			</fieldset>
    Le formulaire est bien pré-rempli, j'ai juste à mettre la date, les buts domiciles, extérieur et le statut du match en fonction de l'id du match.

    J'ai construit ma page update_match de cette façon :

    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
    <?php
    	{ 
    	       // lancement de la requête
    		$req = $bdd->prepare('
    		UPDATE match 
    		SET date="'.$_POST['date'].'", 
    		buts_dom="'.$_POST['buts_dom'].'", 
    		buts_ext="'.$_POST['buts_ext'].'", 
    		id_match_statut="'.$_POST['id_match_statut'].'"
    		WHERE id="'.$_POST['match_id'].'"'); 
     
    		$req->execute(array(
    		'date' => $_POST['date'], 
    		'buts_dom' => $_POST['buts_dom'], 
    		'buts_ext' => $_POST['buts_ext'], 
    		'id_match_statut' => $_POST['id_match_statut']
    		));
     
        // Redirection vers la page d'administration
    	header('Location: admin_match.php');
    	}   
    ?>
    J'ai les messages :

    Notice: Undefined index: id_match_statut in F:\wampee\www\xxx\admin\update_match.php on line 23
    Notice: Undefined index: match_id in F:\wampee\www\xxx\admin\update_match.php on line 24
    Notice: Undefined index: id_match_statut in F:\wampee\www\xxx\admin\update_match.php on line 30
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' in F:\wampee\www\xxx\admin\update_match.php on line 31
    PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match SET date="28/05/2011 ", buts_dom="0 ", buts_ext="4 ", id_m' at line 1 in F:\wampee\www\xxx\admin\update_match.php on line 31
    ça fait deux heures que j'y suis et je ne vois pas le bout

    Si quelqu'un à une idée ?

  2. #2
    Membre averti

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 242
    Points : 354
    Points
    354
    Par défaut
    Sans trop m'avancer, je crois que tu as mal compris comment fonctionner la méthode "prepare" de PDO (vu ton exception, j'en déduis que tu utilises bien PDO).
    Regarde cette page http://php.net/manual/fr/pdo.prepare.php
    Il faut mettre des ":variable" et pas "$_POST["variable"]".

    Peut être quelque chose dans ce goût là :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    $req = $bdd->prepare('
    		UPDATE match 
    		SET date= :date, 
    		buts_dom= :but_doms, 
    		buts_ext= :buts_ext, 
    		id_match_statut= :id_match_statut
    		WHERE id=:match_id');
    Vérifie bien les autres requêtes aussi !

  3. #3
    Membre éprouvé
    Avatar de Gecko
    Homme Profil pro
    Développeur décisionnel
    Inscrit en
    Décembre 2008
    Messages
    499
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur décisionnel

    Informations forums :
    Inscription : Décembre 2008
    Messages : 499
    Points : 1 277
    Points
    1 277
    Par défaut
    Ta requête est mal formée, en gros il faut faire comme ça pour passer des variables tout en garantissant un minimum de sécurité.

    Code php : 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
     
    <?php
    	{ 
    	       // lancement de la requête
                    $sql = 'UPDATE match 
                                SET date = :date, 
                                    buts_dom = :buts_dom, 
    		                buts_ext = :buts_ext, 
    		                id_match_statut = :id_match_statut
                                WHERE id = :match_id'
    		$req = $bdd->prepare($sql); 
    		$req->bindValue(':date',$_POST['date']);
                    $req->bindValue(':but_dom',$_POST['buts_dom']);
                    $req->bindValue(':but_dom',$_POST['buts_ext']);
                    $req->bindValue(':id_match_statut',$_POST['id_match_statut']);
                    $req->bindValue(':match_id',$_POST['match_id']);
    		$req->execute();
                    // Redirection vers la page d'administration
                    header('Location: admin_match.php');
    	}   
    ?>

    Prend l'habitude de séparer la requête sql de la fonction PDO::prepare() c'est plus propre.

    Voici un petit lien vers bindValue(), tu comprendras son utilité ^^

    Dernière chose, je ne sais pas si tu l'as fait ici, mais prend l'habitude d'utiliser les blocs try/catch, ça te permettra de mieux gérer les exceptions

    Toine
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    if ($toBe || !$toBe) echo 'That is the question';

    Mes projets: DVP I/O

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 29
    Points : 12
    Points
    12
    Par défaut
    Oh la la ! vous m'avez complètement perdu, j'ai passé 2h à comprendre mais il doit me manquer quelque chose.

    Je pense avoir compris votre principe mais j'ai des nouvelle erreurs

    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
    <?php
    	{ 
    	       // lancement de la requête
    		$req = $bdd->prepare(
    		'UPDATE match 
    				SET date = :date, 
    				buts_dom = :buts_dom, 
    				buts_ext = :buts_ext, 
    				WHERE id = :match_id'
    		); 
    		$req->bindValue(':date',$_POST['date']);
    		$req->bindValue(':but_dom',$_POST['buts_dom']);
    		$req->bindValue(':but_dom',$_POST['buts_ext']);
    		$req->bindValue(':match_id',$_POST['match_id']);
    		$req->execute();
                    // Redirection vers la page d'administration
    		header('Location: admin_match.php');
    	}   
    ?>
    J'ai l'erreur :

    ( ! ) Notice: Undefined index: match_id in I:\wampee\www\xxx\admin\update_match.php on line 28
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in I:\wampee\www\xxx\admin\update_match.php on line 29
    PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in I:\wampee\www\xxx\admin\update_match.php on line 29
    Vous avez une idée ?

    Je vous remets mon formulaire au cas où

    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
    			<fieldset>
    					<legend>Mise à jour d'un match</legend>
    				<table>
    <?php
        $req = $bdd->prepare('
    	SELECT match.id AS `match_id`, journee, DATE_FORMAT(date, \'%d/%m/%Y\') AS date, dom.nom AS `dom_nom`, ext.nom AS `ext_nom`,  buts_dom, buts_ext, id_match_statut
    	FROM `match`, `equipe` AS dom, `equipe` AS ext, `match_statut` AS statut
    	WHERE id_equipe_dom=dom.id 
    	AND id_equipe_ext=ext.id 
    	AND match.id=\'' . $_GET['match_id'] . '\'
    	GROUP BY match.id
    	');
        $req->execute(array($_GET['match_id']));
    	while ($donnees = $req->fetch())
    	{
    ?>
    				<form action="update_match.php" method="post">
    				<tr>
    					<td>
    						<label for="match_id">ID du match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["match_id"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="journee">Journée</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["journee"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="date">Date</label> : 
    					</td>
    					<td>
    						<input type="text" name="date" id="date" size="10" value="<?php echo ''.$donnees["date"].' ';?>"/>  (exemple 31/07/2011)
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="dom_nom">Match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["dom_nom"].' ';?> - <?php echo ''.$donnees["ext_nom"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="buts_dom">Score</label> : 
    					</td>
    					<td>
    						<input type="text" name="buts_dom" id="buts_dom" size="3" value="<?php echo ''.$donnees["buts_dom"].' ';?>"/> - <input type="text" name="buts_ext" id="buts_ext" size="3" value="<?php echo ''.$donnees["buts_ext"].' ';?>"/>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="id_match_statut">Statut</label> : 
    					</td>
    					<td>
    						<select name="id_match_statut" id="id_match_statut" value="<?php echo ''.$donnees["id_match_statut"].' ';?>"/>
    					<option value="1" <?php if ($donnees["id_match_statut"] == "1") {echo("selected");}?> >Match à jouer</option>
    					<option value="2" <?php if ($donnees["id_match_statut"] == "2") {echo("selected");}?> >Match joué</option>
    					<option value="3" <?php if ($donnees["id_match_statut"] == "3") {echo("selected");}?> >Forfait domicile</option>
    					<option value="4" <?php if ($donnees["id_match_statut"] == "4") {echo("selected");}?> >Forfait exterieur</option></select>
    					</td>
    				</tr>
    				<tr>
    				<td>
                    	<a href="admin_match.php"><img src="../images/retour.png" alt="Retour" title="Retour" /></a>
    				</td>
    				<td>
    					<input type="submit" value="Mettre à jour"/>
    				</td>
    <?php
    //On ferme la boucle while
     }
    ?>
    				</table>
    			</fieldset>

  5. #5
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    pourquoi tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AND match.id=\'' . $_GET['match_id'] . '\'
    et après

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $req->execute(array($_GET['match_id'])
    ???

    y'a un gros soucis la

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 29
    Points : 12
    Points
    12
    Par défaut
    En faite, j'ai un écran précédent qui admin_match.php qui envoi sur le formulaire du match

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td><?php echo '<a href="admin_update_match.php?match_id=' . htmlspecialchars($donnees['match_id']) . '"><img src="../images/modif_small.png" alt="Modification" title="Modifier le match" /></a>'?></td>
    J'arrive donc sur la page admin_update_match.php avec un variable $_GET['match_id']

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $req->execute(array($_GET['match_id'])
    me sers à récupérer ma variable pour ma condition.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AND match.id=\'' . $_GET['match_id'] . '\'
    C'est pour que mon select n'affiche que mon match

    Je viens de tester en faisant

    et ça marche aussi donc effectivement je l'ai mis deux fois pour rien.

  7. #7
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    pourquoi faire une requete préparée si tu ne prépares rien ?
    et le problème de sécurité est toujours la...

  8. #8
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 29
    Points : 12
    Points
    12
    Par défaut
    J'ai fait mon update directement sans préparer la requête, juste pour voir si ça marche, je sécuriserais quand ça marcheras.

    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
    <?php
    	{ 
    	       // lancement de la requête
    		$bdd->exec(
    		'UPDATE match 
    				SET date = \'' . $_POST['date'] . '\', 
    				buts_dom = \'' . $_POST['buts_dom'] . '\', 
    				buts_ext = \'' . $_POST['buts_ext'] . '\',
    				id_match_statut = \'' . $_POST['id_match_statut'] . '\'
    				WHERE id = \'' . $_POST['match_id'] . '\''
    		); 
                    // Redirection vers la page d'administration
    		header('Location: admin_match.php');
    	}   
    ?>
    j'ai les erreurs
    ( ! ) Notice: Undefined index: match_id in F:\wampee\www\xxx\admin\update_match.php on line 24
    ( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' in F:\wampee\www\xxx\admin\update_match.php on line 25
    ( ! ) PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match SET date = '31/07/2011', buts_dom = ' 1', buts_ext = '1'' at line 1 in F:\wampee\www\xxx\admin\update_match.php on line 25
    Il me trouve bien les données que je rentre pour faire la mise à jour (date, buts_dom et buts_ext mais ni mon match.id, ni mon id_match_statut soit les deux propriétés pour lesquelles j'ai fait un AS dans mon select de la page admin_update_match.php.

    Dans mon formulaire POST, j'ai bien les bonne variables :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    					<td>
    						<label for="match_id">ID du match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["match_id"].' ';?>
    					</td>
    et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    					<td>
    						<select name="id_match_statut" id="id_match_statut" value="<?php echo ''.$donnees["id_match_statut"].' ';?>"/>
    					<option value="1" <?php if ($donnees["id_match_statut"] == "1") {echo("selected");}?> >Match à jouer</option>
    					<option value="2" <?php if ($donnees["id_match_statut"] == "2") {echo("selected");}?> >Match joué</option>
    					<option value="3" <?php if ($donnees["id_match_statut"] == "3") {echo("selected");}?> >Forfait domicile</option>
    					<option value="4" <?php if ($donnees["id_match_statut"] == "4") {echo("selected");}?> >Forfait exterieur</option></select>
    					</td>

  9. #9
    Expert éminent sénior

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Points : 10 726
    Points
    10 726
    Par défaut
    vérifie tes données en faisant un print_r($_POST), tu dois échapper les valeurs de ta requete avec PDO::quote

  10. #10
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 29
    Points : 12
    Points
    12
    Par défaut
    Si je fais un print_r, j'obtiens :
    Array ( [date] => [buts_dom] => 1 [buts_ext] => 1 [id_match_statut] => 1 )
    il me manque donc ma variable id.
    Le souci c'est que je ne la mets pas dans mon formulaire, je ne fais que l'afficher, comment je peux faire pour la transférer ?

  11. #11
    Membre éprouvé
    Avatar de Gecko
    Homme Profil pro
    Développeur décisionnel
    Inscrit en
    Décembre 2008
    Messages
    499
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur décisionnel

    Informations forums :
    Inscription : Décembre 2008
    Messages : 499
    Points : 1 277
    Points
    1 277
    Par défaut
    Citation Envoyé par Actraiser Voir le message
    Oh la la ! vous m'avez complètement perdu, j'ai passé 2h à comprendre mais il doit me manquer quelque chose.

    Je pense avoir compris votre principe mais j'ai des nouvelle erreurs

    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
    <?php
    	{ 
    	       // lancement de la requête
    		$req = $bdd->prepare(
    		'UPDATE match 
    				SET date = :date, 
    				buts_dom = :buts_dom, 
    				buts_ext = :buts_ext, 
    				WHERE id = :match_id'
    		); 
    		$req->bindValue(':date',$_POST['date']);
    		$req->bindValue(':but_dom',$_POST['buts_dom']);
    		$req->bindValue(':but_dom',$_POST['buts_ext']);
    		$req->bindValue(':match_id',$_POST['match_id']);
    		$req->execute();
                    // Redirection vers la page d'administration
    		header('Location: admin_match.php');
    	}   
    ?>
    J'ai l'erreur :
    ( ! ) Notice: Undefined index: match_id in I:\wampee\www\xxx\admin\update_match.php on line 28
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in I:\wampee\www\xxx\admin\update_match.php on line 29
    PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in I:\wampee\www\xxx\admin\update_match.php on line 29

    Vous avez une idée ?

    Je vous remets mon formulaire au cas où

    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
    			<fieldset>
    					<legend>Mise à jour d'un match</legend>
    				<table>
    <?php
        $req = $bdd->prepare('
    	SELECT match.id AS `match_id`, journee, DATE_FORMAT(date, \'%d/%m/%Y\') AS date, dom.nom AS `dom_nom`, ext.nom AS `ext_nom`,  buts_dom, buts_ext, id_match_statut
    	FROM `match`, `equipe` AS dom, `equipe` AS ext, `match_statut` AS statut
    	WHERE id_equipe_dom=dom.id 
    	AND id_equipe_ext=ext.id 
    	AND match.id=\'' . $_GET['match_id'] . '\'
    	GROUP BY match.id
    	');
        $req->execute(array($_GET['match_id']));
    	while ($donnees = $req->fetch())
    	{
    ?>
    				<form action="update_match.php" method="post">
    				<tr>
    					<td>
    						<label for="match_id">ID du match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["match_id"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="journee">Journée</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["journee"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="date">Date</label> : 
    					</td>
    					<td>
    						<input type="text" name="date" id="date" size="10" value="<?php echo ''.$donnees["date"].' ';?>"/>  (exemple 31/07/2011)
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="dom_nom">Match</label> : 
    					</td>
    					<td>
    						<?php echo ''.$donnees["dom_nom"].' ';?> - <?php echo ''.$donnees["ext_nom"].' ';?>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="buts_dom">Score</label> : 
    					</td>
    					<td>
    						<input type="text" name="buts_dom" id="buts_dom" size="3" value="<?php echo ''.$donnees["buts_dom"].' ';?>"/> - <input type="text" name="buts_ext" id="buts_ext" size="3" value="<?php echo ''.$donnees["buts_ext"].' ';?>"/>
    					</td>
    				</tr>
    				<tr>
    					<td>
    						<label for="id_match_statut">Statut</label> : 
    					</td>
    					<td>
    						<select name="id_match_statut" id="id_match_statut" value="<?php echo ''.$donnees["id_match_statut"].' ';?>"/>
    					<option value="1" <?php if ($donnees["id_match_statut"] == "1") {echo("selected");}?> >Match à jouer</option>
    					<option value="2" <?php if ($donnees["id_match_statut"] == "2") {echo("selected");}?> >Match joué</option>
    					<option value="3" <?php if ($donnees["id_match_statut"] == "3") {echo("selected");}?> >Forfait domicile</option>
    					<option value="4" <?php if ($donnees["id_match_statut"] == "4") {echo("selected");}?> >Forfait exterieur</option></select>
    					</td>
    				</tr>
    				<tr>
    				<td>
                    	<a href="admin_match.php"><img src="../images/retour.png" alt="Retour" title="Retour" /></a>
    				</td>
    				<td>
    					<input type="submit" value="Mettre à jour"/>
    				</td>
    <?php
    //On ferme la boucle while
     }
    ?>
    				</table>
    			</fieldset>
    Si tu regardes ma requête tu verras que je me suis planté en mettant deux fois le même attribut.
    Voici la requête comme il faut :
    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
    <?php
    	{ 
    	       // lancement de la requête
    		$req = $bdd->prepare(
    		'UPDATE match 
    				SET date = :date, 
    				buts_dom = :buts_dom, 
    				buts_ext = :buts_ext, 
    				WHERE id = :match_id'
    		); 
    		$req->bindValue(':date',$_POST['date']);
    		$req->bindValue(':buts_dom',$_POST['buts_dom']);
    		$req->bindValue(':buts_ext',$_POST['buts_ext']);
    		$req->bindValue(':match_id',$_POST['match_id']);
    		$req->execute();
                    // Redirection vers la page d'administration
    		header('Location: admin_match.php');
    	}   
    ?>
    Pour l’erreur citée plus haut elle est simple, ça dis que le nombre de paramètres "binValue('xxx',$xxx);" ne correspondes pas entre la requêtes sql et la déclaration dans le script.
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    if ($toBe || !$toBe) echo 'That is the question';

    Mes projets: DVP I/O

Discussions similaires

  1. [MySQL] Requête SQL qui ne passe pas (UPDATE)
    Par ZeWiz dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 04/09/2014, 13h25
  2. Commande SQL qui ne fait pas update ?
    Par Battosaiii dans le forum PL/SQL
    Réponses: 1
    Dernier message: 27/07/2011, 15h23
  3. [JNI] Java ne trouve pas mes méthodes natives
    Par carotte31 dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 14/06/2006, 21h47
  4. IE qui ne trouve pas un element
    Par darktears dans le forum Général JavaScript
    Réponses: 13
    Dernier message: 17/01/2006, 19h21
  5. REquete sans erreur sql qui n'agit pas ........
    Par Skam dans le forum Langage SQL
    Réponses: 7
    Dernier message: 02/02/2005, 13h41

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