Source : lesson_13_a2_create_password_table.php |
Résultat |
<?php require ("../commons/connect_to_db.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']) ) { echo "<form action=$_SERVER[PHP_SELF] method=post>"; ?> <table><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</td> <td><input type="text" size="2" 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 { $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']; $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>"; } echo "</table>"; echo "<p><a href=lesson_13_b_login_form.php> Saisie user/mot de passe pour entrer sur le site</a><br/>"; } ?>
|
|