supprimer (löschen) un produit de ma liste

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : supprimer (löschen) un produit de ma liste

Re: supprimer (löschen) un produit de ma liste

par Henrigo » 04 nov. 2016, 09:31

bonjour j'ai eu entre temps a modifier mon code de drucker_remove.php mais il ne marche toujours pas . voici a quoi cela ressemble.
<?php
require_once __DIR__ . '/connection.php';

$id = isset($_POST['id']) ? $_POST['id'] : '';
$img_id    = $_POST['img_id'];
$img_path  = $_POST['img_path'];
$type      = $_POST['type'];
$user_id   = $_POST['user_id'];
$sessionID = $_POST['sessionID'];


$data = array();      // array to pass back data

$check = $dbConnect->prepare('DELETE FROM drucker 
WHERE id      = :prod_id
AND img_id    = :img_id
AND img_path  = :img_path
AND type      = :type
AND user_id   = :user_id
AND sessionID = :sessionID');


$check->bindValue(':prod_id',          $id);
$check->bindValue(':img_id',       $img_id);
$check->bindValue(':img_id',       $img_id);
$check->bindValue(':img_path',   $img_path);
$check->bindValue(':type',           $type);
$check->bindValue(':user_id',     $user_id);
$check->bindValue(':sessionID', $sessionID);

if ($check->execute() === true) {
    $data['success'] = true;
} else {
    $data['success'] = false;
}

// return all our data to an AJAX call
echo json_encode($data);
?>

Re: supprimer (löschen) un produit de ma liste

par Henrigo » 02 nov. 2016, 15:37

ce serait bien plus simple, pour supprimer, de passer un seul paramètre, l'id du produit.
quel est le contenu généré par cette boucle : while ($prod = $req->fetch(PDO::FETCH_ASSOC)) { ?>
les champs cachés ont-ils la valeur attendue ?
salut
juste avec l'id ca ne marche pas , voila a quoi ressemble le contenu de la boucle while ($prod = $req->fetch(PDO::FETCH_ASSOC)) { ?>

Array
(
[id] => 15
[prod_id] => 7
[img_id] => 13
[img_path] => Kantteil2.png
[type] => variant
[user_id] => 13
[sessionID] => 97fd21c9428e249f606a71ed1abb7661
[zeit] => 2016-10-31 14:52:58
)

Re: supprimer (löschen) un produit de ma liste

par or 1 » 02 nov. 2016, 15:16

ce serait bien plus simple, pour supprimer, de passer un seul paramètre, l'id du produit.
quel est le contenu généré par cette boucle : while ($prod = $req->fetch(PDO::FETCH_ASSOC)) { ?>
les champs cachés ont-ils la valeur attendue ?

supprimer (löschen) un produit de ma liste

par Henrigo » 02 nov. 2016, 14:27

salut a tous,

la question je l'ai deja posé cette question une fois ici, j'éssaye cette fois d'être court.
quand j'essaye de vouloir supprimer un produit de ma liste il supprime toujour le premier produit
se trouvant sur ma liste et non le produit donc j'aimerai supprimé.

voici a quoi ressemble:
drucker.php
<?php
require_once __DIR__ . '/connection.php';

$id        = $_POST['id'];
$img_id    = $_POST['img_id'];
$type      = $_POST['type'];
$user_id   = $_POST['user_id'];
$sessionID = $_POST['sessionID'];
$location  = $_POST['location'];
$path      = $_POST['img_path'];
$time      = $_POST['time'];

$check = $dbConnect->prepare('SELECT COUNT(*) FROM drucker 
WHERE prod_id = :id
AND img_id    = :img_id
AND img_path  = :img_path
AND type      = :type
AND user_id   = :user_id
AND sessionID = :sessionID');

$check->bindValue(':id',               $id);
$check->bindValue(':img_id',       $img_id);
$check->bindValue(':img_path',       $path);
$check->bindValue(':type',           $type);
$check->bindValue(':user_id',     $user_id);
$check->bindValue(':sessionID', $sessionID);
$check->execute();

if ((int)$check->fetchColumn() === 0) {
    $stm = $dbConnect->prepare('INSERT INTO drucker (prod_id, img_id, img_path, type, user_id, sessionID, zeit) VALUES (:prod_id, :img_id, :img_path, :type, :user_id, :sessionID, :time)');
    $stm->bindValue(':prod_id',          $id);
    $stm->bindValue(':img_id',       $img_id);
    $stm->bindValue(':img_path',       $path);
    $stm->bindValue(':type',           $type);
    $stm->bindValue(':user_id',     $user_id);
    $stm->bindValue(':sessionID', $sessionID);
    $stm->bindValue(':time',           $time);
    $stm->execute();
}

header("Location:" . $location);?>
drucker_remove.php
<?php
require_once __DIR__ . '/connection.php';

$img_id = $_POST['img_id'];
$img_path = $_POST['img_path'];
$type = $_POST['type'];
$user_id = $_POST['user_id'];
$sessionID = $_POST['sessionID'];


$data = array();      // array to pass back data

$check = $dbConnect->prepare('DELETE FROM drucker 
WHERE img_id  = :img_id
AND img_path  = :img_path
AND type      = :type
AND user_id   = :user_id
AND sessionID = :sessionID');

$check->bindValue(':img_id', $img_id);
$check->bindValue(':img_path', $img_path);
$check->bindValue(':type', $type);
$check->bindValue(':user_id', $user_id);
$check->bindValue(':sessionID', $sessionID);
//$check->execute();

if ($check->execute() === true) {
    $data['success'] = true;
} else {
    $data['success'] = false;
}

// return all our data to an AJAX call
echo json_encode($data);
?>
a ce niveau c'est morceau de code que je vous presente a quoi ressemble ma requête
et la <form></form> donc la suppression se passe
<?php 
$req = $dbConnect->query('SELECT * FROM drucker WHERE sessionID = "' . $session . '"');

$i = 1;
        while ($prod = $req->fetch(PDO::FETCH_ASSOC)) { ?>
            <tr>
                    <form class="remove" method="post" action="drucker_remove.php" name="<?php echo $prod['id'] ?>">
                        <input type="hidden" name="img_id" value="<?php echo $prod['img_id'] ?>">
                        <input type="hidden" name="type" value="<?php echo($prod['type']) ?>">
                        <input type="hidden" name="img_path" value="<?php echo($prod['img_path']) ?>">
                        <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id'] ?>">
                        <input type="hidden" name="sessionID" value="<?php echo $_SESSION['sessionID'] ?>">
                        <input type="submit" value="Löschen" name="remove_img">
                    </form>
            </tr>

        <?php } ?>
Franchemnent j'ai besoin de votre aide, je suis bloqué a ce niveau

Merci bien