too long


I am having an issue with a form. I have a database, and with a form I get all the data from the clients with the php function foreach.

On the action page (invoice.php), I can display all the selected items, but every time I put the quantity for each items, it only displays the last text box I filled.

I don't know how to explain it any more, so here's my code:

form.php :

    <input type="text" name="txtbox[<?php echo $input->id_article; ?>]" value="<?php echo $input->id_article; ?>" placeholder="1" style="text-align: center; width:30px;"></input>

        <input
            type="checkbox" 
            name="checked_articles[]"
            value="<?php echo $input->id_article; ?>">
        <?php echo "(".
                        ($input->ref_article).")".
                        ($input->nom_article)." (".
                        ($input->prix_article)." €)"; ?><br>
  <?php endforeach; ?>


invoice.php (header with the mysql data queries):

if(isset($_POST['checked_articles'])){
foreach($_POST['checked_articles'] as $chkbx){
$sql_articles = 'SELECT * FROM articles WHERE id_article="'.$chkbx.'"';
$req_articles = mysql_query($sql_articles) or die('Erreur SQL !<br>'.$sql_articles.'<br>'.mysql_error());
$data_articles[] = mysql_fetch_assoc($req_articles);
}}


$textbox = $_POST['txtbox'][$chkbx];


invoice.php (where the datas are displayed):

<?php foreach ($data_articles as $input) : ?>
    <tr>
        <td><?php echo $input['ref_article']; ?></td>
        <td><?php echo $input['nom_article']; ?></td>
        <td><?php echo $textbox; ?></td> <!-- Where I want the quantity to be displayed -->
        <td><?php echo $input['prix_article']; ?> €</td>
        <td><?php echo $input['prix_article']*$textbox; ?> €</td>
    </tr>
    <?php endforeach; ?>




I want to display, for each selected items, the quantity the users put on the text box.

Any help would be highly apprecied !
Thank you!

From the looks of your code, $textbox is an array filled with ids, like this:

Array
(
    [txtbox] => Array
        (
            [1] => 1
            [2] => 1
            [3] => 1
        )

)

In you foreach you need to reference the value with the article id, like this:

<td><?php echo $_POST['txtbox'][$input['id_article']]; ?></td>

Also, you should look into preventing sql injection. The id in you sql is passed directly from the post.

Hope it helps.