Bonjour à tous,

J'ai un formulaire comme ceci

Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
<form method="post" name="formAchat">
<input type="hidden" class="inputtext1" name="id_prod" value="<?php echo $achat2->id;?>">
<input type="hidden" class="inputtext1" name="id_membre" value="<?php echo $_SESSION['id_membre'];?>">
<input type="text" class="inputtext1" name="id_vendeur" value="<?php echo $achat2->id_membre;?>">
Qts. : <input type="text" name="qte" size="4" value="1">
<input type="submit" style="font-size : 9px;"  value="Achat" />
</form>

Mon code Jquery

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
$(document).ready(function() {
    $("form[name='formAchat']").submit(function(event) { //Trigger on form submit
        $('#id_prod + .throw_error').empty(); //Clear the messages first
		$('#id_membre + .throw_error').empty(); //Clear the messages first
		$('#id_vendeur + .throw_error').empty(); //Clear the messages first
		$('#qte + .throw_error').empty(); //Clear the messages first
        $('#success').empty();
 
            //Validate fields if required using jQuery
 
        var formAchat = { //Fetch form data
			'qte'  : $('input[name=qte]').val(), //Store name fields value
            'id_prod'  : $('input[name=id_prod]').val(), //Store name fields value
			'id_membre'  : $('input[name=id_membre]').val(), //Store name fields value
			'id_vendeur'  : $('input[name=id_vendeur]').val() //Store name fields value
        };
 
        $.ajax({ //Process the form using $.ajax()
            type        : 'POST', //Method type
            url         : 'ajax/achat_code.php', //Your form processing file url
            data        : formAchat, //Forms name
            dataType    : 'json',
            success     : function(data) {
 
            if (!data.success) { //If fails
				if (data.errors.qte) { //Returned if any error from process.php
                    $('.throw_error').fadeIn(1000).html(data.errors.qte); //Throw relevant error
                }
 
                if (data.errors.id_prod) { //Returned if any error from process.php
                    $('.throw_error').fadeIn(1000).html(data.errors.id_prod); //Throw relevant error
                }
				if (data.errors.id_membre) { //Returned if any error from process.php
                    $('.throw_error').fadeIn(1000).html(data.errors.id_membre); //Throw relevant error
                }
				if (data.errors.id_vendeur) { //Returned if any error from process.php
                    $('.throw_error').fadeIn(1000).html(data.errors.id_vendeur); //Throw relevant error
                }
            } else {
                    $('#success').fadeIn(1000).append('<p>' + data.posted + '</p>'); //If successful, than throw a success message
					//window.setTimeout("location=('deconnexion.php');",8000);
                }
            }
        });
        event.preventDefault(); //Prevent the default submit
    });
});

formulaire achat_code.php

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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
session_start();
setlocale(LC_TIME, 'fr_FR.ISO_8859-1');
date_default_timezone_set('Europe/Paris');
include_once('../includes/fonctions.php'); 
$nomsite = "Ultra Code Discount";
$debug = true; 
$errors = array(); //To store errors
$form_data = array(); //Pass back the data to `form.php`
$id_prod = array();
$id_vendeur = array();
 
/* Validate the form on server side */
if ($_POST['id_prod']) { //Name cannot be empty
 
$id_prod = intval($_POST['id_prod']);
$id_vendeur = intval($_POST['id_vendeur']);
$info101 = $db->prepare('SELECT * FROM codetyp WHERE id = :id_prod');
		$info101->bindValue('id_prod',$id_prod, PDO::PARAM_INT);
		$info101->execute();
		$membre101=$info101->fetch(PDO::FETCH_OBJ); 
 
$codes2 = $db->prepare('SELECT * FROM codes WHERE type = :id_code AND id_vendeur = :id_vendeur AND utilisation = :util ');
		$codes2->bindValue('id_code',$membre101->id_code, PDO::PARAM_INT);
		$codes2->bindValue('id_vendeur',$id_vendeur, PDO::PARAM_INT);
		$codes2->bindValue('util','0', PDO::PARAM_INT);
        $codes2->execute(); 
		$nbentrees = $codes2->rowCount();
 
if($nbentrees != ''){
$errors['id_prod'] = $nbentrees.'-'.$id_prod; 
 
}else{
$errors['id_prod'] = "Stock Insufissant";
}
}
if (!empty($errors)) { //If errors in validation
    $form_data['success'] = false;
    $form_data['errors']  = $errors;
} else { //If not, process the form, and return true on success
    $form_data['success'] = true;
if($form_data['success'] == true){
 
$info = $db->prepare('SELECT * FROM membres WHERE id_membre = ?');
		$info->bindValue(1,$_POST['id_membre'], PDO::PARAM_INT);
		$info->execute();
		$membre=$info->fetch(PDO::FETCH_OBJ); 
 
$info10 = $db->prepare('SELECT * FROM codetyp WHERE id = ?');
		$info10->bindValue(1,$_POST['id_prod'], PDO::PARAM_INT);
		$info10->execute();
		$membre10=$info10->fetch(PDO::FETCH_OBJ); 
 
 
$quantite = intval($_POST['qte']);
 
$total = $quantite * $membre10->prix;
$codes = $db->prepare('SELECT * FROM codes WHERE type = ? AND id_vendeur = ? AND utilisation = ? LIMIT ' . $quantite);
        $codes->bindValue(1,$membre10->id_code, PDO::PARAM_INT);
		$codes->bindValue(2,$_POST['id_vendeur'], PDO::PARAM_INT);
		$codes->bindValue(3,'0', PDO::PARAM_INT);
        $codes->execute(); 
		$nbentrees = $codes->rowCount();
        while($codeach=$codes->fetch(PDO::FETCH_OBJ)) {
                 $coderip1[] = $codeach->code;
                 $coderip12[] = $codeach->id_code;
 
 
for($i=0;$i<$nbentrees;$i++) {
 
$nouvdemande1 = $db->prepare('UPDATE codes SET utilisation=:utilisation, id_membre=:id_membre where code=:code');
                    $nouvdemande1->bindValue('utilisation','1', PDO::PARAM_INT);
					$nouvdemande1->bindValue('id_membre',$_POST['id_membre'], PDO::PARAM_INT);
                    $nouvdemande1->bindValue('code',$codeach->code, PDO::PARAM_INT);
                    $nouvdemande1->execute();	
 
$form_data['posted'] = $coderip1;
 
}
}
$addClient1 =  $db->prepare("INSERT INTO achat_codes (id_membre,id_vendeur,timetemps,id_code,codes,montant,nbr_code) VALUES (:id_membre,:id_vendeur,:timetemps,:id_code,:codes,:montant,:nbr_code)");
                $addClient1->bindParam('id_membre',$_SESSION['id_membre'], PDO::PARAM_INT);
				$addClient1->bindParam('id_vendeur',$_POST['id_vendeur'], PDO::PARAM_INT);
                $addClient1->bindParam('timetemps',time(), PDO::PARAM_INT);
                $addClient1->bindParam('id_code',$_POST['id_prod'], PDO::PARAM_INT);
                $addClient1->bindParam('codes',implode(',',array_values($coderip1)), PDO::PARAM_INT);
                $addClient1->bindParam('montant',$total, PDO::PARAM_INT);
                $addClient1->bindParam('nbr_code',$_POST['qte'], PDO::PARAM_INT);               
                //$addClient1->execute();
}		
 
}
 
//Return the data back to form.php
echo json_encode($form_data);
 
?>

Mon probleme c'est que le formulaire m'envoi toujour l'ID 1 et pas les autre ID
Dans la base j'ai deux id 1 et 10 et quand je test il me donne que l'id 1

Pouvez vous me dire pkoi