Source : lesson_13_a2_add_in_password_table.php |
Résultat |
<?php require ("../mysql_connexion/mysql_connexion.php"); require ("../commons/functions.php"); //mysql_select_db($db) ; $tableName = "atelierphp_sol_pass_words" ;
if (!isset($_POST['user_name']) or !isset($_POST['password']) or !checkdate($_POST['expiration_month'], $_POST['expiration_day'],$_POST['expiration_year']) ) { $param = "lesson_13_a2_add_in_password_table.php"; echo "<form action=show_solutions.php?exercise=$param method=post>"; //echo "<form action=$_SERVER[PHP_SELF] method=post>"; ?> <table><tr><th colspan=2>Ajouter un nouvel utilisateur dans la table des mots de passe :</th></tr> <tr> <td><small>Nom d'utilisateur</td> <td><input type="text" size="10" name="user_name"></td> </tr> <tr> <td><small>Mot de passe</td> <td><input type="PASS_WORD" size="10" name="password"> </td> </tr> <tr> <td><small>Date d'expiration:<br/>Jour en un ou deux chiffres </td> <td><input type="text" size="2" name="expiration_day"></td> </tr> <tr> <td><small>Date d'expiration : <br/>Mois en 2 chiffres</td> <td><input type="text" size="2" name="expiration_month"></td> </tr> <tr> <td><small>Date d'expiration : <br/>Année sur 4 chiffres <font color=red><b> Compris entre 2000 et 2040 !</b></font></td> <td><input type="text" size="4" name="expiration_year"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="submit" value="Valider"></td> </tr> </form> </table> </center> <?php } else { echo "**********!! <br/>"; $user_name = $_POST['user_name'] ; $password = crypt($_POST['password'],$user_name) ; $expiration_day =$_POST['expiration_day']; $expiration_month =$_POST['expiration_month']; $expiration_year =$_POST['expiration_year']; if ($expiration_year > 2040 ) {$expiration_year = 2040;} if ($expiration_year < 2000 ) {$expiration_year = 2000;} $expiration_date = mktime(0,0,0, $expiration_month,$expiration_day,$expiration_year); $result = mysqli_query($mysqli,"INSERT INTO atelierphp_sol_pass_words (PASS_WORD_USER, PASS_WORD_PASS, PASS_WORD_EXPIRATION_DATE) VALUES ('$user_name','$password', '$expiration_date')") or mySQLdie(); if ($result == 1) { echo "**********Value inserted <br/>"; } else { echo "**********Error inserting in the table <br/>"; } //read the table echo "<table border=1><tr><th>User</th><th>Pass</th> <th>Exp timestamp</th><th>Exp date</th></tr>"; $result = mysqli_query($mysqli,"SELECT * FROM atelierphp_sol_pass_words "); $fields = mysqli_num_fields($result); while ($row=mysqli_fetch_array($result)) { echo "<tr>"; for($i=0;$i<$fields;$i++) { echo "<td>$row[$i]</td>"; $expiration_date = $row[$i]; } echo "<td>".date("d/m/Y",$row[$fields-1]). "</td></tr>"; } $param = "lesson_13_b_login_form.php"; echo "</table><p>"; echo "<a href=show_solutions.php?exercise=$param> Saisie utilisateur/mot de passe pour entrer sur le site </a><br/>"; } ?>
|
|