La pagina index.php contiene entrambi i codici postati prima ed è collegata a insert.php dove c'è il codice per l'inserimento dei dati nel db.
Quindi index.php è questo:
Questo invece è insert.phpcodice:<?php // Imposto la lunghezza della password a 10 caratteri $lung_pass = 10; // Creo un ciclo for che si ripete per il valore di $lung_pass for ($x=1; $x<=$lung_pass; $x++) { // Se $x è multiplo di 2... if ($x % 2){ $mypass = $mypass . chr(rand(97,122)); // Se $x non è multiplo di 2... }else{ // Aggiungo alla password un numero compreso tra 0 e 9 $mypass = $mypass . rand(0,9); } } // echo $mypass ?> <table width="400" border="0" align="center" cellpadding="3" cellspacing="1"> <tr> <td>Inserimento dati </td> </tr> </table> <table width="400" border="0" align="left" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="insert.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td width="16%">Cognome</td> <td width="2%">:</td> <td width="82%"><input name="cognome" type="text" id="cognome" size="50"></td> </tr> <tr> <td>Nome</td> <td>:</td> <td><input name="nome" type="text" id="nome" size="50"></td> </tr> <tr> <td>Cellulare</td> <td>:</td> <td><input name="cellulare" type="text" id="cellulare" size="50"></td> </tr> <tr> <td><input type="hidden" value="<? echo $mypass; ?>" name="password" id="password" size="50"></td> </tr> <tr> <td></td> <td></td> <td><input type="submit" name="Invia" value="Invia"> <input type="reset" name="Cancella" value="Cancella"></td> </tr> </table> </form> </td> </tr> </table>
codice:<?php $con = mysql_connect("localhost","root","master01"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("form", $con); $sql="INSERT INTO test (cognome, nome, cellulare, password) VALUES ('$_POST[cognome]','$_POST[nome]','$_POST[cellulare]','$_POST[mypass]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?>

Rispondi quotando