Search code examples
phpsqldatabasepostget

Update an ID after getting it with GET


PHP part:

if (!empty($_GET['ID_personne'])) {
    $id = checkInput($_GET['ID_personne']);
}
// ....................

if (!empty($_POST)) {
    $CIN = checkInput($_POST['CIN']);
    // ................
    $statement = $db->prepare("UPDATE personnes  
                                set 
                                ID_personne =:cin, 
                                Nom = :nom, 
                                Prenom = :prenom, 
                                Telephone = :telephone, 
                                Mail = :mail,
                                Categorie=:categorie,
                                Type=:type
                                WHERE ID_personne = :id");

    $statement->bindValue(':cin',$CIN);
    $statement->bindValue(':nom',$nom);
    $statement->bindValue(':prenom',$prenom);
    $statement->bindValue(':telephone',$telephone);
    $statement->bindValue(':categorie',$categorie);
    $statement->bindValue(':mail',$mail);
    $statement->bindValue(':type',$type);
    $statement->bindValue(':id',$id);

    $statement->execute();
    header("Location: personnes.php");
}

HTML part:

<!-- ............. -->
<form class="form" action="update_personnes.php" role="form" 
    method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label for="CIN">CIN:</label>
        <input maxlength="8" minlength="8" type="text" class="form- 
  control" id="CIN" name="CIN" placeholder="CIN" value="<?php echo $CIN;?>">
        <!-- ............... -->

NB: The points mean that there is code, but it is useless for resolving my error. I wanna update my id after filling the form, then clicking on modify, it doesn't work even for the other columns BUT:

if I change this line:

 $statement->bindValue(':id',$id);

with

 $statement->bindValue(':id',$CIN);

the other columns change whereas the ID didn't change.


Solution

  • i change the form in the HTML part and it works:

                 <form class="form" action="<?php echo 'update_personnes.php?ID_personne='.$id ?>" role="form" method="post" enctype="multipart/form-data">