Source: lesson_13_a3_create_password_table.php | Résultat |
<?php require ("../mysql_connexion/mysql_connexion.php"); //mysql_select_db($db) ; echo "<table border=1><tr><th>User</th><th>Pass</th></tr>"; $result = mysqli_query($mysqli,"select * from atelierphp_exe_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>"; } echo "</tr>"; } echo "</table>"; $param = "lesson_13_b_login_form.php"; echo "<br/> <a href=../commons/show_exercises.php?exercise=$param> Saisie user/mot de passe pour entrer sur le site</a><br/>"; ?>
Fichier : ../commons/connect_to_db.php
<?php @include ("../mysql_connexion/mysql_connexion.php"); @include ("../../mysql_connexion/mysql_connexion.php"); function mySQLdie($error = "") { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); global $strError,$strSQLQuery ; global $strMySQLSaid, $strBack, $sql_query;
echo "<b> Error : $strError </b>"; if(isset($sql_query) && !empty($sql_query)) { echo "$strSQLQuery: <pre>$sql_query</pre><p>"; } if(empty($error)) echo $strMySQLSaid.mysqli_error($mysqli); else echo $strMySQLSaid.$error; echo "<br/><a href=\"javascript:history.go(-1)\"> $strBack</a>"; exit; } ?>
Fichier : ../commons/functions.php
<?php // Pour savoir si une table existe function mySQLtable_exist($tableName) { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); $query = "SELECT COUNT(*) FROM $tableName"; $result = mysqli_query($mysqli,$query); $num_rows = @mysqli_num_rows($result); if($num_rows) { echo "<small>La table existait déjà <br/>"; return TRUE; } else { echo "<small>La table n'existait pas <br/>"; return FALSE; } } // Supprime une table avec message approprié //attention $tableName et non $table_name function drop_table($tableName) { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); echo "Efface table ".$tableName."<br/>"; $result = mysqli_query($mysqli,"DROP TABLE $tableName") ; if ($result == 1) { echo "Table effacée <br/>"; } else { echo "Erreur en effaçant the table<br/>"; } } // Insère un enregistrement dans une table function insert_a_row_1 ($table_name, $field_name_1, $field_name_2, $field_1, $field_2) { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); $result = mysqli_query($mysqli,"INSERT INTO $table_name ($field_name_1,$field_name_2) VALUES ('$field_1','$field_2')"); if ($result == 1) { echo "valeur $field_2 insérée dans $field_name_2 <br/>"; } else { echo "erreur lors de l'insersion $field_2 dans la table $table_name <br/>"; } } function insert_a_row_2 ($table_name, $field_name_1, $field_name_2, $field_name_3, $field_1, $field_2, $field_3) { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); $result = mysqli_query($mysqli,"INSERT INTO $table_name ($field_name_1,$field_name_2,$field_name_3) VALUES ('$field_1','$field_2','$field_3')"); if ($result == 1) { echo "value $field_2 inserted in $field_name_2 <br/>"; } else { echo "error inserting $field_2 in the table $table_name <br/>"; } } //lecture d'une table function readTable ($tableName,$field_1,$field_2="",$field_3="", $field_4="",$field_5="") { global $mysqli; require_once("../mysql_connexion/mysql_connexion.php"); echo "Lecture de la table $tableName :"; echo "<table border=1><tr><th>$field_1 </th><th>$field_2</th> <th>$field_3</th><th>$field_4</th> <th>$field_5</th></tr>"; $result=mysqli_query($mysqli,"select * from $tableName "); $fields = mysqli_num_fields($result); while ($row=mysqli_fetch_array($result)) { echo "<tr>"; for($i=0;$i<$fields;$i++) { echo "<td>$row[$i]</td>"; } echo "</tr>"; } echo "</table>"; } ?>
| User | Pass |
---|
Laura | laura_pass | Maria | maria_pass |
Saisie user/mot de passe pour entrer sur le site
|