mardi 26 septembre 2017

How to merge values ​to a checkbox or solve it with 2 query or foreach (i don't know)

I have a table (name: tabella) in mysql db (EXAMPLE: IMAGE) with a checkbox and a form (and other data that aren't useful now). I need to insert quantita[] in a other table (name: tabella1) with selected[]. The values of quantita field ​​can be edited (it is an input type=number). but when I pass the data to inserisci.php it gives back all quantita data from TABELLA and not the new values SELECTED... I don't know if I explained it well (I deleted everything that was not useful and I don't know if it works as well as now).

<?
echo "<form action='inserisci.php' method='post'>"; 

foreach ($pdo->query("SELECT * FROM tabella") as $row) {
echo "
<input type='checkbox' name='selected[]' value='{$row['id']}'/>
<input type='number' min='1' max='99' autocomplete='off' name='quantita[]' value='{$row['quantita']}'/>";
}
?>
<td align="left"><input style="width:100px;" type="submit" value="Inserisci"/>
        </form>

inserisci.php

foreach($_POST['selected'] as $check) {
        $query = $pdo->prepare("INSERT INTO tabella1 (prodotto, quantita) VALUES ((SELECT prodotto FROM tabella WHERE ID=$check))");
        $query->execute();}




Aucun commentaire:

Enregistrer un commentaire