Premesso che sono un autodidatta e quindi ne capisco non tantissimo chiedo aiuto per riuscire a fare quanto segue in un piccolo db.
l'utente inserisce nella pagina1 il suo codice fiscale, nella pagina 2 legge i suoi dati e se vuole può modificarli, la pagina 3 da conferma della modifica.
funziona tutto eccetto per il fatto che non scrive nella riga del db
ho usato i form e le sessioni per fare il tutto
dove sbaglio?
pagina1
pagina2codice:<body> <p>inserisci il tuo codice fiscale</p> <form id="form1" name="form1" method="post" action="pagina2.php"> <label> <input name="CF" type="text" id="CF" /> </label> <label> <input type="submit" name="Submit" value="Cerca" /> </label> </form> </body>
pagina3codice:<?php session_start(); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento senza titolo</title></head> <body> <table width="100%"> <tr> <td> <? $CF = $_POST['CF']; $_SESSION['CF'] = $CF; mysql_connect("localhost" ,"nome_db", "")or die("Impossibile caricare db. Riprova più tardi"); $test = mysql_connect("localhost" ,"nome_db", ""); mysql_select_db("my_nome_db")or die("Impossibile selezionare il database. Riprova più tardi"); $sql = "SELECT * FROM ALUNNI WHERE CF = '".$CF."' "; $result = mysql_query($sql, $test); $trovati = mysql_num_rows($result); if($trovati>0) {while(($row = mysql_fetch_assoc($result))) { ?> <table width="100%" border="0"> <tr> <td width="50%"> Benvenuto <strong> <? echo '' . $row[NOME] . ' '; echo '' . $row[COGNOME]. ''; ?> </strong></td> <td width="50%"><div align="right">Codice Fiscale <strong> <? echo $row[CF]; ?> </strong> </div></td> </tr> </table> <p>I tuoi dati in nostro possesso sono i seguenti:</p> <p>Data di nascita <strong> <? echo $row[DATA_NASCITA]; ?> </strong></p> <p>Luogo di nascita<strong> <? echo $row[LUOGO_NASCITA]; ?> </strong></p> <p>I dati per contattarti in nostro possesso sono:</p> <table width="100%" border="0"> <tr> <td>E-mail<form id="form1" name="form1" method="post" action="pagina3.php"> <label> <input name="MAIL" type="text" id="MAIL" value=" <? echo $row[MAIL]; ?> " /> </label> <label> <input type="submit" name="Submit1" value="Modifica" /> </label> </form></td> </tr> </table> <? } else { echo "Siamo spiacenti ma il codice fiscale inserito non è nel nostro archivio."; } ?> </td> </tr> </table> </body> </html>
codice:<?php session_start(); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento senza titolo</title></head> <body> <table width="100%"> <tr> <td> <?php $MAIL = $_POST['MAIL']; $_SESSION['CF']; mysql_connect("localhost" ,"nome_db", "")or die("Impossibile caricare db. Riprova più tardi"); $test = mysql_connect("localhost" ,"nome_db", ""); mysql_select_db("my_nome_db")or die("Impossibile selezionare il database. Riprova più tardi"); $sql = "UPDATE ALUNNI SET MAIL = '".$MAIL."' WHERE CF = '".$_SESSION['CF']."'" ; $result = mysql_query($sql); echo "mail aggiornata"; ?> </td> </tr> </table> </body> </html>

Rispondi quotando