mercredi 27 septembre 2017

how combine field (input type=text) with checkbox

WHAT I HAVE

I have this table: TABLE EXAMPLE Whose fields are populated by a mysql database. name of table TABELLA

HTML

<form action='inserisci.php' method='post'
   <input type='checkbox' name='selected[]' value='{$row['id']}'/>
   <input type='number' min='1' max='99' autocomplete='off' name='quantita[]' value='".substr($row['quantita'],3)."'/>
<input style="width:100px;" type="submit" value="Inserisci"/>

PHP INCOMPLETE but work without any quantita results

inserisci.php

if(!empty($_POST['selected'])) { //Se ci sono spunte
    foreach($_POST['selected'] as $check) {
        $query = $pdo->prepare("INSERT INTO tabella1 (nome, cognome, prodotto) VALUES ('$nome','$cognome', (SELECT prodotto FROM tabella WHERE ID=$check))");
        $query->execute();

WHAT I NEED

I need to combine selected[] (CHECKBOX) value with quantita[] and insert all in TABELLA1.

I wish also that the values ​​(quantita) from TABELLA to be displayed in field...so that they can be modified (if needed) and be included in the database along with the other values

FOR EXAMPLE (with quantita):

("INSERT INTO tabella1 (nome, cognome, prodotto, quantita) VALUES ('$nome','$cognome', (SELECT prodotto FROM tabella WHERE ID=$check), '$quantita')") 

How i can do that?




Aucun commentaire:

Enregistrer un commentaire