Ciao raga,
ho un file salva.php che preleva tramite POST i dati inseriti in delle form e li inserisce in un database,
questo il codice :
Vorrei fare in modo che dopo l'inserimento il programma recuperasse l'id appena registrato e lo passasse alla pagina stampa.php per generare la stampa del documento
questo il codice del file stampa.php
ho un file salva.php che preleva tramite POST i dati inseriti in delle form e li inserisce in un database,
questo il codice :
Codice:
<?php
// INCLUDO IL FILE PER LA CONNESSIONE AL DATABASE
include ("conn.php");
//Effettuo l'Escape dei campi _POST
foreach ($_POST as $key => $value) {
$_POST[$key] = mysql_real_escape_string($value);
}
// EFFETTUO L'UPPER CASE DEI CAMPI INSERITI
foreach ($_POST as $key => $value) {
$_POST[$key] = strtoupper($value);
}
$veicolo = $_POST['veicolo'];
$targa = $_POST['targa'];
$km = $_POST['km'];
$telaio = $_POST['telaio'];
$cliente = $_POST['cliente'];
$indirizzo = $_POST['indirizzo'];
$piva = $_POST['piva'];
$tel = $_POST['tel'];
$itr1 = $_POST['itr1'];
$itr2 = $_POST['itr2'];
$itr3 = $_POST['itr3'];
$itr4 = $_POST['itr4'];
$itr5 = $_POST['itr5'];
$itr6 = $_POST['itr6'];
$itr7 = $_POST['itr7'];
$itr8 = $_POST['itr8'];
$itr9 = $_POST['itr9'];
$itr10 = $_POST['itr10'];
$itr11 = $_POST['itr11'];
$itr12 = $_POST['itr12'];
$itr13 = $_POST['itr13'];
$itr14 = $_POST['itr14'];
$itr15 = $_POST['itr15'];
$for1 = $_POST['for1'];
$for2 = $_POST['for2'];
$for3 = $_POST['for3'];
$for4 = $_POST['for4'];
$for5 = $_POST['for5'];
$for6 = $_POST['for6'];
$for7 = $_POST['for7'];
$for8 = $_POST['for8'];
$for9 = $_POST['for9'];
$for10 = $_POST['for10'];
$for11 = $_POST['for11'];
$for12 = $_POST['for12'];
$for13 = $_POST['for13'];
$for14 = $_POST['for14'];
$for15 = $_POST['for15'];
$imp_1 = $_POST['imp_1'];
$imp_2 = $_POST['imp_2'];
$imp_3 = $_POST['imp_3'];
$imp_4 = $_POST['imp_4'];
$imp_5 = $_POST['imp_5'];
$imp_6 = $_POST['imp_6'];
$imp_7 = $_POST['imp_7'];
$imp_8 = $_POST['imp_8'];
$imp_9 = $_POST['imp_9'];
$imp_10 = $_POST['imp_10'];
$imp_11 = $_POST['imp_11'];
$imp_12 = $_POST['imp_12'];
$imp_13 = $_POST['imp_13'];
$imp_14 = $_POST['imp_14'];
$imp_15 = $_POST['imp_15'];
$totale = $_POST['totale'];
$n_tecnico = $_POST['n_tecnico'];
$data = $_POST['data'];
// QUERY DI INSERIMENTO SENZA UPPER, L'UPPER E' DEMANDATO AL COMANDO FOREACH
$sql = "INSERT INTO `CommesseO` (`veicolo`,`targa`,`km`,`telaio`,`cliente`,`indirizzo`,`piva`,`tel`,`itr1`,`itr2`,`itr3`,`itr4`,`itr5`,`itr6`,`itr7`,`itr8`,`itr9`,`itr10`,`itr11`,`itr12`,`itr13`,`itr14`,`itr15`,`for1`,`for2`,`for3`,`for4`,`for5`,`for6`,`for7`,`for8`,`for9`,`for10`,`for11`,`for12`,`for13`,`for14`,`for15`,`imp_1`,`imp_2`,`imp_3`,`imp_4`,`imp_5`,`imp_6`,`imp_7`,`imp_8`,`imp_9`,`imp_10`,`imp_11`,`imp_12`,`imp_13`,`imp_14`,`imp_15`,`totale`,`n_tecnico`,`data`)
VALUES
(('$veicolo'),('$targa'),'$km',('$telaio'),('$cliente'),('$indirizzo'),'$piva','$tel',('$itr1'),('$itr2'),('$itr3'),('$itr4'),('$itr5'),('$itr6'),('$itr7'),('$itr8'),('$itr9'),('$itr10'),('$itr11'),('$itr12'),('$itr13'),('$itr14'),('$itr15'),('$for1'),('$for2'),('$for3'),('$for4'),('$for5'),('$for6'),('$for7'),('$for8'),('$for9'),('$for10'),('$for11'),('$for12'),('$for13'),('$for14'),('$for15'),$imp_1, $imp_2, $imp_3, $imp_4, $imp_5, $imp_6, $imp_7, $imp_8, $imp_9, $imp_10, $imp_11, $imp_12, $imp_13, $imp_14, $imp_15, $totale,('$n_tecnico'),STR_TO_DATE('$data', '%d/%m/%Y'))";
// Lanciamo la query:
$result = mysql_query($sql);
// controllo l'esito
if (!$result) {
die("Errore nella query $sql: " . mysql_error());
}
else
echo '</br>';
echo '</br>';
echo '</br>';
echo "<center><h3><font color=\"red\">I dati da te inseriti sono stati correttamente registrati</center>\n";
echo "<center><h3><font color=\"red\">Prosegui con il menù a destra</h3></center>\n";
echo '</br>';
// E chiudiamo la connessione a MySQL
mysql_close();
?>
Vorrei fare in modo che dopo l'inserimento il programma recuperasse l'id appena registrato e lo passasse alla pagina stampa.php per generare la stampa del documento
questo il codice del file stampa.php
Codice:
// INCLUDO IL FILE PER LA CONNESSIONE AL DATABASE
include ("conn.php");
//Preparo la query di modifica
$sql = "SELECT * , DATE_FORMAT(Commesse.data,'%d/%m/%Y') as data FROM Commesse WHERE id='$_SESSION[id]'";
// Lanciamo la query:
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0)
{
echo "Non ho trovato niente con questo id: ".$_SESSION['id'];
echo "<br />";
echo "La query eseguita è: ".$sql;
exit;
}
$dati = mysql_fetch_assoc ($result);
$id = $dati ['id'];
$veicolo = $dati['veicolo'];
$targa = $dati['targa'];
$km = $dati['km'];
$telaio = $dati['telaio'];
$cliente = $dati['cliente'];
$indirizzo = $dati['indirizzo'];
$piva = $dati['piva'];
$tel = $dati['tel'];
$itr1 = $dati['itr1'];
$itr2 = $dati['itr2'];
$itr3 = $dati['itr3'];
$itr4 = $dati['itr4'];
$itr5 = $dati['itr5'];
$itr6 = $dati['itr6'];
$itr7 = $dati['itr7'];
$itr8 = $dati['itr8'];
$itr9 = $dati['itr9'];
$itr10 = $dati['itr10'];
$itr11 = $dati['itr11'];
$itr12 = $dati['itr12'];
$itr13 = $dati['itr13'];
$itr14 = $dati['itr14'];
$itr15 = $dati['itr15'];
$for1 = $dati['for1'];
$for2 = $dati['for2'];
$for3 = $dati['for3'];
$for4 = $dati['for4'];
$for5 = $dati['for5'];
$for6 = $dati['for6'];
$for7 = $dati['for7'];
$for8 = $dati['for8'];
$for9 = $dati['for9'];
$for10 = $dati['for10'];
$for11 = $dati['for11'];
$for12 = $dati['for12'];
$for13 = $dati['for13'];
$for14 = $dati['for14'];
$for15 = $dati['for15'];
$imp_1 = $dati['imp_1'];
$imp_2 = $dati['imp_2'];
$imp_3 = $dati['imp_3'];
$imp_4 = $dati['imp_4'];
$imp_5 = $dati['imp_5'];
$imp_6 = $dati['imp_6'];
$imp_7 = $dati['imp_7'];
$imp_8 = $dati['imp_8'];
$imp_9 = $dati['imp_9'];
$imp_10 = $dati['imp_10'];
$imp_11 = $dati['imp_11'];
$imp_12 = $dati['imp_12'];
$imp_13 = $dati['imp_13'];
$imp_14 = $dati['imp_14'];
$imp_15 = $dati['imp_15'];
$totale = $dati['totale'];
$n_tecnico = $dati['n_tecnico'];
$data = $dati['data'];
// controllo l'esito
if (!$result) {
die("Errore nella query $sql: " . mysql_error());
}
// E chiudiamo la connessione a MySQL
mysql_close();
?>
<FORM name Commessa method="POST" action="../stampa.php">
<fieldset>
<legend>Anagrafica Cliente</legend>
<div id="anagrafica">
<table>
<tr>
<td width="99">Id</td>
<td width="495"><input name="id" disabled="disabled" id="id" value="<?php echo $id ?>" size="10" readonly="readonly"></td>
<td width="99">Data Intervento</td>
<td><input type="text" name="data" class="datepicker" required="required" id="data" value="<?php echo $data ?>"></td>
</tr>
<tr>
<td>Cliente</td>
<td><input name="cliente" class="uppercase" id="cliente" value="<?php echo $cliente ?>"></td>
<td>Indirizzo</td>
<td><input name="indirizzo" class="uppercase" id="indirizzo" value="<?php echo $indirizzo ?>"></td>
</tr>
<tr>
<td>Partita Iva</td>
<td><input name="piva" class="uppercase" id="piva" maxlength="12" value="<?php echo $piva ?>"></td>
<td>Telefono</td>
<td><input name="tel" class="uppercase" id="tel" value="<?php echo $tel ?>"></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Anagrafica Vettura</legend>
<table>
<td width="99">Veicolo</td>
<td width="145"><input name="veicolo" class="uppercase" id="veicolo" value="<?php echo $veicolo ?>"></td>
<td>Targa</td>
<td><input name="targa" required="required" class="uppercase" id="targa" value="<?php echo $targa ?>"></td>
</tr>
<tr>
<td>Telaio</td>
<td><input name="telaio" class="uppercase" id="telaio" value="<?php echo $telaio ?>"></td>
<td>Km</td>
<td width="495"><input name="km" class="uppercase" id="km" value="<?php echo $km ?>"></td>
</tr>
<tr>
<td width="99">Nome tecnico</td>
<td width="278"><input name="n_tecnico" required="required" class="uppercase" id="n_tecnico" value="<?php echo $n_tecnico ?>"></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Interventi di manutenzione veicolo</legend>
<table>
<td>Intervento</td>
<td>Fornitore</td>
<td>Importo</td>
</tr>
<tr>
</tr>
<tr>
<td><input name="itr1" class="uppercase" id="itr1" size="40" value="<?php echo $itr1 ?>"></td>
<td><input name="for1" class="uppercase" id="for1" size="25" value="<?php echo $for1 ?>"></td>
<td><input name="imp_1" id="imp_1" size="10" value="<?php echo $imp_1 ?>"></td>
</tr>
<tr>
<td><input name="itr2" class="uppercase" id="itr2" size="40" value="<?php echo $itr2 ?>"></td>
<td><input name="for2" class="uppercase" id="for2" size="25" value="<?php echo $for2 ?>"></td>
<td><input name="imp_2" id="imp_2" size="10" value="<?php echo $imp_2 ?>"></td>
</tr>
<tr>
<td><input name="itr3" class="uppercase" id="itr3" size="40" value="<?php echo $itr3 ?>"></td>
<td><input name="for3" class="uppercase" id="for3" size="25" value="<?php echo $for3 ?>"></td>
<td><input name="imp_3" id="imp_3" size="10" value="<?php echo $imp_3 ?>"></td>
</tr>
<tr>
<td><input name="itr4" class="uppercase" id="itr4" size="40" value="<?php echo $itr4 ?>"></td>
<td><input name="for4" class="uppercase" id="for4" size="25" value="<?php echo $for4 ?>"></td>
<td><input name="imp_4" id="imp_4" size="10" value="<?php echo $imp_4 ?>"></td>
</tr>
<tr>
<td><input name="itr5" class="uppercase" id="itr5" size="40" value="<?php echo $itr5 ?>"></td>
<td><input name="for5" class="uppercase" id="for5" size="25" value="<?php echo $for5 ?>"></td>
<td><input name="imp_5" id="imp_5" size="10" value="<?php echo $imp_5 ?>"></td>
</tr>
<tr>
<td><input name="itr6" class="uppercase" id="itr6" size="40" value="<?php echo $itr6 ?>"></td>
<td><input name="for6" class="uppercase" id="for6" size="25" value="<?php echo $for6 ?>"></td>
<td><input name="imp_6" id="imp_6" size="10" value="<?php echo $imp_6 ?>"></td>
</tr>
<tr>
<td><input name="itr7" class="uppercase" id="itr7" size="40" value="<?php echo $itr7 ?>"></td>
<td><input name="for7" class="uppercase" id="for7" size="25" value="<?php echo $for7 ?>"></td>
<td><input name="imp_7" id="imp_7" size="10" value="<?php echo $imp_7 ?>"></td>
</tr>
<tr>
<td><input name="itr8" class="uppercase" id="itr8" size="40" value="<?php echo $itr8 ?>"></td>
<td><input name="for8" class="uppercase" id="for8" size="25" value="<?php echo $for8 ?>"></td>
<td><input name="imp_8" id="imp_8" size="10" value="<?php echo $imp_8 ?>"></td>
</tr>
<tr>
<td><input name="itr9" class="uppercase" id="itr9" size="40" value="<?php echo $itr9 ?>"></td>
<td><input name="for9" class="uppercase" id="for9" size="25" value="<?php echo $for9 ?>"></td>
<td><input name="imp_9" id="imp_9" size="10" value="<?php echo $imp_9 ?>"></td>
</tr>
<tr>
<td><input name="itr10" class="uppercase" id="itr10" size="40" value="<?php echo $itr10 ?>"></td>
<td><input name="for10" class="uppercase" id="for10" size="25" value="<?php echo $for10 ?>"></td>
<td><input name="imp_10" id="imp_10" size="10" value="<?php echo $imp_10 ?>"></td>
</tr>
<tr>
<td><input name="itr11" class="uppercase" id="itr11" size="40" value="<?php echo $itr11 ?>"></td>
<td><input name="for11" class="uppercase" id="for11" size="25" value="<?php echo $for11 ?>"></td>
<td><input name="imp_11" id="imp_11" size="10" value="<?php echo $imp_11 ?>"></td>
</tr>
<tr>
<td><input name="itr12" class="uppercase" id="itr12" size="40" value="<?php echo $itr12 ?>"></td>
<td><input name="for12" class="uppercase" id="for12" size="25" value="<?php echo $for12 ?>"></td>
<td><input name="imp_12" id="imp_12" size="10" value="<?php echo $imp_12 ?>"></td>
</tr>
<tr>
<td><input name="itr13" class="uppercase" id="itr13" size="40" value="<?php echo $itr13 ?>"></td>
<td><input name="for13" class="uppercase" id="for13" size="25" value="<?php echo $for13 ?>"></td>
<td><input name="imp_13" id="imp_13" size="10" value="<?php echo $imp_13 ?>"></td>
</tr>
<tr>
<td><input name="itr14" class="uppercase" id="itr14" size="40" value="<?php echo $itr14 ?>"></td>
<td><input name="for14" class="uppercase" id="for14" size="25" value="<?php echo $for14 ?>"></td>
<td><input name="imp_14" id="imp_14" size="10" value="<?php echo $imp_14 ?>"></td>
</tr>
<tr>
<td><input name="itr15" class="uppercase" id="itr15" size="40" value="<?php echo $itr15 ?>"></td>
<td><input name="for15" class="uppercase" id="for15" size="25" value="<?php echo $for15 ?>"></td>
<td><input name="imp_15" id="imp_15" size="10" value="<?php echo $imp_15 ?>"></td>
</tr>
<td></td>
<td align="center"><input type="button" value="Calcola Totale" onClick="javascript:sum();"></td>
<td><input name="totale" type="text" required="required" size="10" value="<?php echo $totale ?>"> </td>
</table>
</fieldset>
<div id="salva">
<input type="image" src="css/img/pdf.png" height="46" width="46" />
</div>
</FORM>
</div> <!-- chiudo il div container -->
</body>
</html>