Ho risolto..
codice:
$pdo = new PDO("mysql:host=127.0.0.1;dbname=farma", 'root', '');
//Presenting the values in a table
echo "<form action='inserisci.php' method='post' enctype='application/x-www-form-urlencoded'>";
echo "<table align='left' border='1' width='60%'>";
echo "<tr><th></th><th>Qnt</th><th>Prodotto</th><th>Term</th></tr>";
foreach ($pdo->query("SELECT * FROM tabella") as $row) {
echo "<tr><td><input type='checkbox' name='selected[]' value='{$row['ID']}'/><br /></td><td>{$row['quantita']}</td><td>{$row['prodotto']}</td><td>{$row['terminale']}</td></tr>";
}
echo "</table><br />";
?>
<h2 align="center">Aggiungi informazioni</h2>
<p><strong>Nome</strong>: <input type="text" name="nome" size="34" tabindex="1" /></p>
<p><strong>Cognome</strong>: <input type="text" name="cognome" size="34" tabindex="2" /></p>
<p><strong>Quantità</strong>: <input type="text" name="quantita" size="28" tabindex="3" /></p>
<p><strong>Numero di Tel.</strong>: <input type="text" name="numero" size="28" tabindex="4" /></p>
<p><strong>Note</strong>: <input type="text" name="note" size="28" tabindex="5" /></p>
<p><input type="submit" value="Aggiungi" tabindex="3"/>
</form></p>
inserisci.php
codice:
if(!empty($_POST['selected'])) {
foreach($_POST['selected'] as $check) {
$query = $pdo->prepare("INSERT INTO tabella1 (prodotto) SELECT prodotto FROM tabella WHERE ID=$check");
$query->execute();
}
}else{ echo"Selezione nulla.";}
Ho provato una query del genere
codice:
$query = $pdo->prepare("INSERT INTO tabella1 SET nome=$nome, cognome=$cognome AND SELECT prodotto FROM tabella WHERE ID=$check");
ma senza risultato