Php->mysql UPDATE ne fonctionne pas (WAMP SERVER)

Résolu
Bonsoir a tous ,

Voilà j'ai un petit problème avec mon code :
(wamp ne détecte rien anormal mais rien ne ce passe quand je le modifie !!)

TABLEAU agenda (id, titre, description, date_choisie)

Page modification.php
<center>
<table border="1">

<thead>
<tr>
<th>

<form action="./agenda_traitement/modification2.php" method="post">
<p><b><u>Modification :</u></b></p>
<p><small>Date et Heure</small></p>
<input type="text" name="date_choisie" maxlength="19" size="20" value="AAAA-MM-JJ HH:MM:SS" style="border:solid 1px black; border-radius:5px; text-align:center; box-shadow:0 0 6px;"/>

<p><small>Titre</small></p>
<input type="text" name="titre" maxlength="30" size="35" style="border:solid 1px black; border-radius:5px; text-align:center; box-shadow:0 0 6px;"/>

<p><small>Description</small></p>
<textarea name="description" rows="10" cols="40" style="border:solid 1px black; border-radius:5px; text-align:center; box-shadow:0 0 6px;"></textarea>
<br/>
<br/>

<input type="reset" value="Effacer">
<input type="submit" value="Valider"/>
</form>
<br/>
</th>
</tr>
</thead>
</table>
<br/>
</center>


Page modification2.php (version 1 marche pas)
<?php

$titre = $_POST['titre'];
$description = $_POST['description'];
$date_choisie = $_POST['date_choisie'];

try
{
	$bdd = new PDO('mysql:host=localhost;dbname=nothings_perfect','root','');
}
catch(Exception $e)
{
	die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('UPDATE agenda SET (titre = :titre, description = :description) WHERE date_choisie = :date_choisie');
$req->execute(array(
	'titre' => $titre,
	'description' => $description,
	'date_choisie' => $date_choisie
	));
?>
<?php echo "le nouveau titre est ".'<b>'.'<u>'.$_POST['titre'].'</b>'.'</u>'; ?>
</br>
<?php echo "la nouvelle description est ".'<b>'.'<u>'.$_POST['description'].'</b>'.'</u>'; ?>
</br>
<?php echo "la date choisie est toujours le ".'<b>'.'<u>'.$_POST['date_choisie'].'</b>'.'</u>'; ?>
</br>
<p>Cliquer <a href="http://localhost/test/index.php">ici<a/> pour revenir a l'agenda</p>


Page modification2.php (version 2 ne marche pas quand meme)
<?php

$titre = $_POST['titre'];
$description = $_POST['description'];
$date_choisie = $_POST['date_choisie'];

try
{
	$bdd = new PDO('mysql:host=localhost;dbname=nothings_perfect','root','');
}
catch(Exception $e)
{
	die('Erreur : '.$e->getMessage());
}
$req = $bdd->prepare('UPDATE agenda SET (titre = :titre, description = :description) WHERE date_choisie = :date_choisie');
$req->bindValue('titre', $titre);
$req->bindValue('description', $description);
$req->bindValue('date_choisie', $date_choisie);
$req->execute();

?>
<?php echo "le nouveau titre est ".'<b>'.'<u>'.$_POST['titre'].'</b>'.'</u>'; ?>
</br>
<?php echo "la nouvelle description est ".'<b>'.'<u>'.$_POST['description'].'</b>'.'</u>'; ?>
</br>
<?php echo "la date choisie est toujours le ".'<b>'.'<u>'.$_POST['date_choisie'].'</b>'.'</u>'; ?>
</br>
<p>Cliquer <a href="http://localhost/test/index.php">ici<a/> pour revenir a l'agenda</p>


pour ce qui veulent tester chez eux
https://www.cjoint.com/?3Brtj0kNDqD

je comprend pas ce qui cloche (et 2 fois en plus)
Cordialement florent

5 réponses

  1. Salut,

    Ici
    <form action="./agenda_traitement/modification2.php">


    Ce n'est pas plutôt :
    <form action="../agenda_traitement/modification2.php">
    ?

    Si ça ne marche toujours pas, avant de vérifier ton SQL, vérifie tes variables POST au début de Page modification2.php (sachant que pour un nom de fichier il vaut mieux ne jamais mettre d'espace, mais plutôt Page-modification2.php par exemple).

    Ecris donc tout en haut de ce fichier, après la balise <?php :

    echo $_POST['titre'];
    echo $_POST['description'];
    echo $_POST['date_choisie'];
    


    Si rien ne s'affiche sur ta page c'est déjà que les variables ne sont aps récupérées.

    @ pluche.
    Fab.
    0
    1. Bonjour

      Tu as des parenthèses en trop dans ta requête
      C'est
      SET colonne1=valeur1, colonne2=valeur2...

      et non pas
      SET (colonne1=valeur1, colonne2=valeur2)..
      .
      0
      1. ca fait 2 fois que tu me sauve la mise
        un ENORME merci a toi :)
        0
        1. Jamais 2 sans 3 ....
          À bientôt ^^
          0