Potreste darmi una mano con questo codice?:
Non va la prima parte: vorrei inserire un record vuoto, utilizzo il comando INSERT INTO sceltaUtente (id) VALUES () ma non funziona.
Inoltre facendo dei tentavi non funzionano nemmeno le query successive : tipo mysql_query("INSERT INTO sceltaUtente (peso) VALUES ('0') WHERE id =".$idConfigurazione")... mysql mi da errore su WHERE id=1 (1 è un numero arbitrario).
Dove sbaglio?
Ecco il codice intero, si tratta di un configuratore che aggiorna una tabella in un database con le scelte effettuate e va avanti aggiornando le pagine con javascript e ajax.
codice:<?php include("config.php"); $connessione = mysql_connect("localhost", $username, $password); @mysql_select_db($database, $connessione) or die("Impossibile selezionare il database"); if ($idConfigurazione == "") { //inizializazione //- insert su tabella sceltaUtente e ci prendiamo il valore del campo id mysql_query("INSERT INTO sceltaUtente (id) VALUES ()") or die(mysql_error()); $result = mysql_query("SELECT MAX(id) as MAXID FROM sceltaUtente") or die(mysql_error()); $row = mysql_fetch_array($result,MYSQL_ASSOC); $idConfigurazione = $row['MAXID']; mysql_query("INSERT INTO sceltaUtente (peso) VALUES ('0') WHERE id =".$idConfigurazione)or die(mysql_error()); mysql_query("INSERT INTO sceltaUtente (prezzo-al-commerciante-iva-esclusa) VALUES ('0') WHERE id=".$idConfigurazione)or die(mysql_error()); mysql_query("INSERT INTO sceltaUtente (prezzo) VALUES ('0') WHERE id=".$idConfigurazione)or die(mysql_error()); //- legge tutti i vari passi della configurazione dalla tabella sceltaUtente e li scrive dentro ad un array $res = mysql_query("SELECT tipo FROM telai") or die(mysql_error()); //inizializzazione di $now $now = 0; } else { $lenght = count($arraySeqPassi);#lcr debug if ($now < $lenght) { //legge parametri passati da ajax $idConfigurazione = $_GET["idConfigurazione"]; $now = $_GET["passo_n"]; $sceltaUtente = $_GET["sceltaUtente"]; $tipo = $_GET["categoriaBici"]; $user = $_GET["user"]; //inserisco la scelta nel db if ($now != 0){ $nomeTabella = $arraySeqPassi["$now"]->$valore; mysql_query("UPDATE sceltaUtente SET ".$nomeTabella." =".$sceltaUtente." WHERE id=".$idConfigurazione); //aumento peso su sceltaUtente(db) $pesoComponente = mysql_query("SELECT peso from".$nomeTabella." WHERE modello=".$sceltaUtente); $pesoParziale = mysql_query("SELECT peso from sceltaUtente WHERE id=".$idConfigurazione); $peso = $pesoParziale+$pesoComponente; mysql_query("UPDATE sceltaUtente SET peso =".$peso." WHERE id=".$idConfigurazione); //aumento prezzo-al-commerciante-iva-esclusa su sceltaUtente(db) $prezzoLungoComponente = mysql_query("SELECT prezzo-commerciante-iva-esclusa from".$nomeTabella." WHERE modello=".$sceltaUtente); $prezzoLungoComponenteParziale = mysql_query("SELECT prezzo-al-commerciante-iva-esclusa from sceltaUtente WHERE id=".$idConfigurazione); $prezzoLungo = $prezzoLungoComponenteParziale+$prezzoLungoComponente; mysql_query("UPDATE sceltaUtente SET prezzo-al-commerciante-iva-esclusa =".$prezzoLungo." WHERE id=".$idConfigurazione); //aumento prezzo (db) $prezzoComponente = mysql_query("SELECT prezzo from".$nomeTabella." WHERE modello=".$sceltaUtente); $prezzoComponenteParziale = mysql_query("SELECT prezzo from sceltaUtente WHERE id=".$idConfigurazione); $prezzo = $prezzoComponenteParziale+$prezzoComponente; mysql_query("UPDATE sceltaUtente SET prezzo =".$prezzo." WHERE id=".$idConfigurazione); } // aggiorna il contatore numero del passo $now++; $nomeTabella = $arraySeqPassi["$now"]->$valore; $leggiModelli = mysql_query("SELECT modello FROM ".$nomeTabella." WHERE tipo=".$tipo) or die(mysql_error()); $arrRisultatoModello = array(); while ($row2 = mysql_fetch_assoc($leggiModelli)) $arrRisultatoModello[] = $row2; //processo l'array con un foreach foreach ($arrRisultatoModello as $valori2){ foreach ($valori2 as $valore2) { //apri for echo ("<a href=\"javascript: load(\"".$idConfigurazione."\",".$now."\", \"".$valore2.", \"".$tipo."\", \"".$user."\")>".$valore2. "</a> </br>"); } } } else { // conteggia i totali // 1 query al db su sceltaUtente per prezzo, prezzo-comm, peso $pesoTotale = mysql_query("SELECT peso from sceltaUtente WHERE id=".$idConfigurazione); $prezzoLungoTotale = mysql_query("SELECT prezzo-al-commerciante-iva-esclusa from sceltaUtente WHERE id=".$idConfigurazione); $prz = mysql_query("SELECT prezzo from sceltaUtente WHERE id=".$idConfigurazione); // 2 crea 3 variabili per prezzo, prezzo-comm, peso //$prz = $array[1];// prezzo al pubblico //$przCom = $array[2];// prezzo commerciante iva escl. //$peso = $array[3];// peso // controllo chi è l'utente connesso // 1 controllo se è user reg // assegno valore a variabile in ambiente html echo ("<div id=\"peso\"> Peso: ".$pesoTotale."</div>"); echo (" "); if ($user != "privato") { //2 query su tabella users : select sconto from users where mezza_password = ".$user // fare query per prendere sconto da database utenti $sconto = mysql_query("SELECT perc-sconto from utenti WHERE nome-utente=".$user)or die(mysql_error()); $przComScontato = /*$przCom*/ $prezzoLungoTotale * $sconto; // 3 // assegno valore a variabile in ambiente html echo ("<div style=\"display: none;\" id=\"prezzi\">"); echo "Prezzo al pubblico consigliato: ".$prz; echo (" "); echo "Prezzo al commerciante iva esclusa: ".$przComScontato; // 4 lancio funzione attiva pulsante anti-spia // @link http://www.webmasterworld.com/forum91/441.htm echo (" <a href=\"#\" onclick=\"pulsantone(\'prezzi\'); return(false);\">Nascondi di nuovo</a></p> </div>"); mysql_close($connessione); } } } //includo user $user = $_GET["user"]; //$arrRisultato = serve x caricare su array tutti i risultati della query $arrRisultatoTipo = array(); // nome cambiato: temp non va mai bene, i nomi variabile devono essere significativi if (mysql_num_rows($res) != 0) { while ($row = mysql_fetch_assoc($res)) $arrRisultatoTipo[] = $row; } else echo "No Records!"; //processo l'array con un foreach foreach ($arrRisultatoTipo as $valori){ foreach ($valori as $valore) { //apri for echo ("<a href=\"javascript: load(\"".$idConfigurazione."\",\"".$now."\", \"".$valore."\", \"".$valore."\",\"".$user."\")>".$valore. "</a> </br>"); } } /* - rilasciare la connessione db */ mysql_close(); ?>

Rispondi quotando