Bonsoir,
Voila mon souci : j'ai un formulaire de connexion (avec session) qui me dirige vers une page rassemblant des enregistrements. Sauf que je souhaite que les informations qui apparaissent ne correspondent qu'à l'utilisateur connecté.
Voici le code pour ma page de connexion :
[IMG]
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 <?php require_once('Connections/MaConnexion.php'); ?> <?php function Verif_magicquotes ($chaine) { if (get_magic_quotes_gpc()) $chaine = stripslashes($chaine); return $chaine; } $message = null; if (isset($_POST['pseudo'])) { $pseudo = (isset($_POST['pseudo']) && trim($_POST['pseudo']) != '')? Verif_magicquotes($_POST['pseudo']) : null; $pass = (isset($_POST['pass']) && trim($_POST['pass']) != '')? Verif_magicquotes($_POST['pass']) : null; if(isset($pseudo,$pass)) { mysql_query("SET NAMES 'utf8'"); $nom = mysql_real_escape_string($pseudo); $password = mysql_real_escape_string($pass); $requete = "SELECT * FROM membres WHERE pseudo = '".$nom."' AND pass = '".$password."'"; $req_exec = mysql_query($requete) or die(mysql_error()); $resultat = mysql_fetch_assoc($req_exec); if (isset($resultat['pseudo'],$resultat['pass'])) { session_start(); $_SESSION['login'] = $pseudo; $message = 'Bonjour '.htmlspecialchars($_SESSION['login']).' <a href = "liste_manga.php">Cliquez ici pour vous connecter</a>'; } else { $message = 'Le pseudo ou le mot de passe sont incorrect'; } } else { $message = 'Les champs Pseudo et Mot de passe doivent être remplis.'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Formulaire de connexion</title> </head> <body> <div id = "connexion"> <form action = "#" method="post"> <h1>Connexion</h1> <p><label for = "pseudo">Pseudo : </label><input type="text" name="pseudo" id="pseudo" /></p> <p><label for = "pass">Mot de passe : </label><input type="password" name="pass" id="pass" /></p> <p><input type="submit" value="Envoyer" id = "valider" /></p> </form> <p id = "message"><?php if(isset($message)) echo $message ?></p> </div> </body> </html>[/IMG]
Voici la page avec le tableau dynamique des données. J'ai mis un echo pour vérifier que ma session est toujours active (pour tester uniquement)
En image ^^ [IMG]
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 <?php require_once('Connections/MaConnexion.php'); ?> <?php session_start(); echo $_SESSION['login']; ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_manga = 10; $pageNum_manga = 0; if (isset($_GET['pageNum_manga'])) { $pageNum_manga = $_GET['pageNum_manga']; } $startRow_manga = $pageNum_manga * $maxRows_manga; mysql_select_db($database_MaConnexion, $MaConnexion); $query_manga = "SELECT * FROM manga"; $query_limit_manga = sprintf("%s LIMIT %d, %d", $query_manga, $startRow_manga, $maxRows_manga); $manga = mysql_query($query_limit_manga, $MaConnexion) or die(mysql_error()); $row_manga = mysql_fetch_assoc($manga); if (isset($_GET['totalRows_manga'])) { $totalRows_manga = $_GET['totalRows_manga']; } else { $all_manga = mysql_query($query_manga); $totalRows_manga = mysql_num_rows($all_manga); } $totalPages_manga = ceil($totalRows_manga/$maxRows_manga)-1; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Document sans titre</title> </head> <body> <table border="1"> <tr> <td>id_manga <a href="ajout_manga.php"><img src="ajouter-icone-5107-16.png" width="16" height="16" alt="ajout_manga"></a></td> <td>nom_manga</td> <td>id_membre</td> <td>nom_auteur</td> <td>nom_editeur</td> </tr> <?php do { ?> <tr> <td><?php echo $row_manga['id_manga']; ?></td> <td><?php echo $row_manga['nom_manga']; ?></td> <td><?php echo $row_manga['id_membre']; ?></td> <td><?php echo $row_manga['nom_auteur']; ?></td> <td><?php echo $row_manga['nom_editeur']; ?></td> </tr> <?php } while ($row_manga = mysql_fetch_assoc($manga)); ?> </table> </body> </html> <?php mysql_free_result($manga); ?>[/IMG]
Et voici la page qui me permet d'ajouter un enregistrement directement depuis ce tableau en cliquant sur un lien
En image ^^ [IMG]
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162 <?php require_once('Connections/MaConnexion.php'); ?> <?php session_start(); echo $_SESSION['login']; ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO manga (nom_manga, nom_auteur, nom_editeur) VALUES (%s, %s, %s)", GetSQLValueString($_POST['nom_manga'], "text"), GetSQLValueString($_POST['nom_auteur'], "text"), GetSQLValueString($_POST['nom_editeur'], "text")); mysql_select_db($database_MaConnexion, $MaConnexion); $Result1 = mysql_query($insertSQL, $MaConnexion) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO manga (nom_manga, id_membre, nom_auteur, nom_editeur) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['nom_manga'], "text"), GetSQLValueString($_POST['id_membre'], "text"), GetSQLValueString($_POST['nom_auteur'], "text"), GetSQLValueString($_POST['nom_editeur'], "text")); mysql_select_db($database_MaConnexion, $MaConnexion); $Result1 = mysql_query($insertSQL, $MaConnexion) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO manga (nom_manga, id_membre, nom_auteur, nom_editeur) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['nom_manga'], "text"), GetSQLValueString($_POST['id_membre'], "text"), GetSQLValueString($_POST['nom_auteur'], "text"), GetSQLValueString($_POST['nom_editeur'], "text")); mysql_select_db($database_MaConnexion, $MaConnexion); $Result1 = mysql_query($insertSQL, $MaConnexion) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO manga (nom_manga, id_membre, nom_auteur, nom_editeur) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['nom_manga'], "text"), GetSQLValueString($_POST['id_membre'], "int"), GetSQLValueString($_POST['nom_auteur'], "text"), GetSQLValueString($_POST['nom_editeur'], "text")); mysql_select_db($database_MaConnexion, $MaConnexion); $Result1 = mysql_query($insertSQL, $MaConnexion) or die(mysql_error()); } mysql_select_db($database_MaConnexion, $MaConnexion); $query_auteur = "SELECT nom_prenom_auteur FROM auteur ORDER BY nom_prenom_auteur ASC"; $auteur = mysql_query($query_auteur, $MaConnexion) or die(mysql_error()); $row_auteur = mysql_fetch_assoc($auteur); $totalRows_auteur = mysql_num_rows($auteur); mysql_select_db($database_MaConnexion, $MaConnexion); $query_editeur = "SELECT nom_editeur FROM editeur ORDER BY nom_editeur ASC"; $editeur = mysql_query($query_editeur, $MaConnexion) or die(mysql_error()); $row_editeur = mysql_fetch_assoc($editeur); $totalRows_editeur = mysql_num_rows($editeur); mysql_select_db($database_MaConnexion, $MaConnexion); $query_manga = "SELECT * FROM manga"; $manga = mysql_query($query_manga, $MaConnexion) or die(mysql_error()); $row_manga = mysql_fetch_assoc($manga); $totalRows_manga = mysql_num_rows($manga); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Document sans titre</title> </head> <body> <form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">Nom_manga:</td> <td><input type="text" name="nom_manga" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Id_membre:</td> <td><input type="text" name="id_membre" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Nom_auteur:</td> <td><select name="nom_auteur"> <?php do { ?> <option value="<?php echo $row_auteur['nom_prenom_auteur']?>" ><?php echo $row_auteur['nom_prenom_auteur']?></option> <?php } while ($row_auteur = mysql_fetch_assoc($auteur)); ?> </select></td> <tr> <tr valign="baseline"> <td nowrap align="right">Nom_editeur:</td> <td><select name="nom_editeur"> <?php do { ?> <option value="<?php echo $row_editeur['nom_editeur']?>" ><?php echo $row_editeur['nom_editeur']?></option> <?php } while ($row_editeur = mysql_fetch_assoc($editeur)); ?> </select></td> <tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Insérer un enregistrement"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> </body> </html> <?php mysql_free_result($auteur); mysql_free_result($editeur); mysql_free_result($manga); ?>[/IMG]
Désoler pour ce pavé :/ Merci d'avance pour vos réponses !










Répondre avec citation
Partager