Visualizzazione dei risultati da 1 a 3 su 3

Discussione: un form multi insert

  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    54

    un form multi insert

    ho questo codice con due tabelle
    la tabella dati personali e la tabella auto
    sono collegato 1 a molti con l'id dei dati personali, cioè un proprietario molte auto.
    ora quando inserisco tutti i dati inserisce i date personali ed una sola auto.
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link href="stile.css" type="text/css" rel="stylesheet" /><meta content="it" http-equiv="Content-Language" /><meta content="text/html; charset=utf-8" http-equiv="Content-Type" />  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">  <script src="//code.jquery.com/jquery-1.10.2.js"></script>  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <div class="menu">        <a class="yellow" href="index.html"><font color="yellow">Home</a>        <a class="yellow" href="elenco.php"><font color="yellow">Elenco</a>        <a class="yellow" href="cerca.php"><font color="yellow">Cerca</a>        </div></head><div id="tabs"><ul class='tabs'>    <li><a href='#tab1'>Dati personali</a></li>    <li><a href='#tab2'>Auto</a></li>    <li><a href='#tab3'>Auto</a></li>  </ul>        <div class="contenitore_tabs"><form method="post" action="index.php" >
       <div id="tab1" class="blocco-tab">        <h2>Dati personali</h2><label><b>Data:</label></b><input id= "data" name="data" type="date" /><br /><label><b>Cognome:</label></b><input id ="cognome" name="cognome" type="text" onChange="javascript:this.value=this.value.toUpperCase();" /> <br /><label><b>Nome:</label></b><input id ="nome" name="nome" type="text" onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><label><b>Data di Nascita:</label></b><input id ="data_nascita" name="data_nascita" type="text" /> <br /><label><b>Luogo :</label></b><input id ="luogo_nascita" name="luogo_nascita" type="text"onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><label><b>Ruolo :</label></b><input id ="ruolo" name="ruolo" type="text"onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><input type="hidden" name="arma" value=""></div>
    <div id="tab2" class="blocco-tab">        <h2>Auto</h2>                <label><b>Tipo:</label></b><input id= "tipo" name="tipo" type="text" /><br /><label><b>Fabbrica:</label></b><input id ="fabbrica" name="fabbrica" type="text" onChange="javascript:this.value=this.value.toUpperCase();" /> <br /><label><b>Modello:</label></b><input id ="modello" name="modello" type="text" onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><label><b>targa:</label></b><input id ="targa" name="targa" type="text" /> <br /><label><b>Stato :</label></b><input id ="stato" name="stato" type="text"onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><input type="hidden" name="arma" value=""></div>
    <div id="tab3" class="blocco-tab">                <h2>Auto</h2>                <label><b>Tipo:</label></b><input id= "tipo" name="tipo" type="text" /><br /><label><b>Fabbrica:</label></b><input id ="fabbrica" name="fabbrica" type="text" onChange="javascript:this.value=this.value.toUpperCase();" /> <br /><label><b>Modello:</label></b><input id ="modello" name="modello" type="text" onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><label><b>targa:</label></b><input id ="targa" name="targa" type="text" /> <br /><label><b>Stato :</label></b><input id ="stato" name="stato" type="text"onChange="javascript:this.value=this.value.toUpperCase();"/> <br /><input type="hidden" name="arma" value=""></div>
    <input name="Submit1" type="submit" value="Invia" /><br />    </form></div><script>$( "#tabs" ).tabs();</script><?phpinclude 'con.php';  if(isset($_POST['Submit1'])){$date_str $_POST['data'];$converted date("Y-m-d"strtotime($date_str));$cognome=addslashes($_REQUEST['cognome']);$nome=addslashes($_REQUEST['nome']);$data_nascita=addslashes($_REQUEST['data_nascita']);$luogo_nascita=addslashes($_REQUEST['luogo_nascita']);$ruolo=addslashes($_REQUEST['ruolo']);$auto=addslashes($_REQUEST['auto']);$fabbrica=addslashes($_REQUEST['fabbrica']);$modello=addslashes($_REQUEST['modello']);$targa=addslashes($_REQUEST['targa']);$stato=addslashes($_REQUEST['stato']);
    $rand rand ();//$residenza=addslashes($_REQUEST['residenza']);$a=mysqli_query($con,"INSERT INTO dati_personali (data, cognome, nome, data_nascita, luogo_nascita, ruolo, codice) VALUES ('$converted','$cognome', '$nome', '".$_REQUEST['data_nascita']."', '$luogo_nascita', '$ruolo','$rand')");$b=   mysqli_query($con,"INSERT INTO auto (id, auto, fabbrica, modello, targa, stato)  VALUES (LAST_INSERT_ID(), '".$auto."', '".$fabbrica."', '".$modello."', '".$targa."','".$stato."')");}  mysqli_close($con);?></body></html>
    mentre se modifico la query così
    Codice PHP:
    $b=   mysqli_query($con,"INSERT INTO auto (id, auto, fabbrica, modello, targa, stato)  VALUES (LAST_INSERT_ID(), '".$auto."', '".$fabbrica."', '".$modello."', '".$targa."','".$stato."'),  (LAST_INSERT_ID(), '".$auto."', '".$fabbrica."', '".$modello."', '".$targa."','".$stato."')");} 
    ne inserisce due. ma solo l'ultima.
    Come posso fare??

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    54

    [risolto] multi insert php

    risolto.
    ho cambiato la query, ovviamente
    Codice PHP:
    $a=mysqli_query($con,"INSERT INTO dati_personali (data, cognome, nome, data_nascita, luogo_nascita, ruolo, codice) VALUES ('$converted','$cognome', '$nome', '".$_REQUEST['data_nascita']."', '$luogo_nascita', '$ruolo','$rand')");$a .=   mysqli_query($con,"INSERT INTO auto (id, auto, fabbrica, modello, targa, stato)  VALUES (LAST_INSERT_ID(), '".$auto."', '".$fabbrica."', '".$modello."', '".$targa."', '".$stato."')");  $a .=   mysqli_query($con,"INSERT INTO auto (id, auto, fabbrica, modello, targa, stato)  VALUES ((select MAX(id) FROM dati_personali), '".$auto1."', '".$fabbrica1."', '".$modello1."', '".$targa1."', '".$stato1."')"); 

  3. #3
    le funzioni mysql dalla versione 7 di php non funzionano più

    EDIT scusa ho letto male

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.