è un pò lungo...ma per lo più sono controlli
codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title> The Box</title> </head> <body> <?php if(!isset($_POST['nome'])): ?> //effettuo l'accesso <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label> Nome utente <input type="text" name="nome" size="40" maxlenght="200"/> età: <input type="number" name="eta" size="3" maxlenght="3" /> password: <input type="password" name="pass" maxlenght="16" /> <input type="submit" value="invia" /> </label> </form> <?php else: ?> //se è un utente registrato <h1> Benvenuto <?php echo $_POST['nome']; ?> </h1> <h2>Leggi tutti i messaggi del nostro sito </h2> <?php $dbcn = @mysql_connect( 'localhost', 'boxmex', 'password'); if(!$dbcn) { echo 'connessione non riuscita'; exit(); } echo ' '; if(!@mysql_select_db('my_box')) {echo 'errore durante la connessione al database'; exit(); } $nome1= $_POST['nome']; $passw= $_POST['pass']; //controllo se l'utente è registrato $risultato1= @mysql_query("SELECT nome FROM utenti WHERE password = '$passw'"); $risultato2=mysql_fetch_array($risultato1); if($risultato2['nome'] != $nome1) { echo 'password errata prova di nuovo a fare il login'; echo $risultato2; } else { $risultato3 =@mysql_query("SELECT testomex FROM messaggi"); if(!$risultato3) { echo 'Problema con la selezione dei messaggi riprova'; } else { $num = mysql_num_rows($risultato3); if(num > 0) { echo 'ok'; // controllo se entro nel ciclo while($row = mysql_fetch_array($risultato3)); { echo ' '; echo '<table width="500" height="200" border="1">'; echo ' <tr>'; echo '<td>' . $row['testomex'] . '<td>'; echo ' </tr>'; echo '</table>'; echo '</p>'; } } } } ?> <?php endif; ?> </div> </body> </html>

Rispondi quotando