-2

I think I have all the syntax correct here but for some reason my table will not update when this code is executed. Does anyone know why?

Here is the code of my php page:

<?php
include_once("connexionMysql.php");
    if(isset($_GET['valider'])){
        $titreIci=$_GET['titre'];
        $idIci=(int)$_GET['id'];
        $preparedStatement = $bdd->prepare("UPDATE AY_albums  SET titre=':titreIci' WHERE id=':idIci'");
        $preparedStatement->bindValue(':titreIci', $titreIci);
        $preparedStatement->bindValue(':idIci', $idIci);
        $preparedStatement->execute();

    }

    header("Location: pageDaccueilAdmin.php");
?>
Andrew Y
  • 23
  • 1
  • 7
  • 3
    Try it without the quotes around the bound parameters, e.g., `SET titre=:titreIci WHERE id=:idIci"` – David Wyly Apr 14 '16 at 18:58
  • 1
    This is a sign you don't have [exceptions turned on](http://php.net/manual/en/pdo.error-handling.php) because otherwise the mistake would have been obvious. Exceptions are hard to ignore and give very useful information about mistakes. – tadman Apr 14 '16 at 18:59
  • Remove the quotes around the parameters. – Tom Apr 14 '16 at 19:02
  • Tried that @DavidWyly and now it just wipes the field in the database. In the previous page which leads to this php page I have forms that the user can modify the initial value of 'titre' in the table. When the user clicks on submit does that mean that the data is not transferring through $_GET correctly? And I'm receiving null as the new value? – Andrew Y Apr 14 '16 at 19:07

1 Answers1

0

You should remove the quotes.

Instead of this:

UPDATE AY_albums  SET titre=':titreIci' WHERE id=':idIci'

Do this:

UPDATE AY_albums  SET titre=:titreIci WHERE id=:idIci
melledijkstra
  • 361
  • 3
  • 17
  • I tried that and now it updates the data in the field to be null. In the previous page which leads to this php page I have forms that the user can modify the initial value of 'titre' in the table. When the user clicks on submit does that mean that the data is not transferring through $_GET correctly? And I'm receiving null as the new value? – Andrew Y Apr 14 '16 at 19:13
  • Figured it out thanks! – Andrew Y Apr 14 '16 at 19:18
  • Good job, glad to help! – melledijkstra Apr 14 '16 at 19:21