-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.php
153 lines (89 loc) · 3.91 KB
/
blog.php
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
<?php session_start();
if(!isset($_SESSION['connecter']))
{
die('vous ete deconnecter');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header> </header>
<div id="centre" >
<form method="post" action="" >
<label >Article</label><textarea type="text" name="article" rows="20" cols="40"> </textarea><br>
<label>Catégorie</label>
<select name="cat" >
<option value=""> ....</option>
<option value="cuisine"> cuisine</option>
<option value="mode"> mode</option>
<option value="astuce_beaute"> astuce beauté</option>
</select> <br>
<label for="pseudo"> </label> <button id="deconnexion1" name="envoyer" >Publier </button>
<button id ="deconnexion" name="deconnexion" > Deconnexion </button>
</form>
</div>
<?php
if (isset ($_POST['deconnexion']) )
{
$_SESSION=array();
session_destroy();
header("location:acceuil.php");
}
try
{
$connexion = new PDO("mysql:host=localhost;dbname=menai", 'root', '');
$connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
echo "Error: " . $e->getMessage();
}
// if(isset($_POST['auteur'])) htmlspecialchars ($auteur= $_POST["auteur"]);
// else $auteur="";
if(isset($_POST['article'])) htmlspecialchars ($article=$_POST["article"]);
else $article="";
if(isset($_POST['cat'])) htmlspecialchars ($cat=$_POST["cat"]);
else $cat="";
if( !empty($article) && !empty($cat) )
{
$req = $connexion->prepare("SELECT id_cat FROM categorie WHERE nom_cat = ?");
$req->execute(array($_POST['cat']));
$row = $req->fetch() ;
// $row["id_cat"];
$reqid= $connexion->prepare("SELECT id_auteur FROM auteur WHERE pseudo = ?");
$reqid->execute(array($_SESSION['pseudo']));
$id = $reqid->fetch() ;
$req2 = $connexion->prepare('INSERT INTO article ( nom_article,id_auteur) VALUES( ?,?)');
$req2->execute(array($_POST['article'],$id["id_auteur"]));
$id_data = $connexion->lastInsertId();
$req3 = $connexion->prepare('INSERT INTO join_articles_categories ( id_article, id_cat) VALUES( ?,?)');
$req3->execute(array($id_data, $row["id_cat"]));
$req4 = $connexion->query('SELECT nom_article FROM article ORDER BY id_article DESC LIMIT 0, 10');
?>
<div id="rose">
<?php
while($row4 = $req4->fetch())
{
?> <div class="article"> <?php echo $row4["nom_article"]."<br>","<br> </div>";
}
}
else
{
?>
<div id="rose"> <h2>LES DERNIERS ARTICLES PUBLIES </h2> <br>
<?php
$req4 = $connexion->query('SELECT nom_article FROM article ORDER BY id_article DESC LIMIT 0, 10');
while($row4 = $req4->fetch())
{
?> <div class="article"> <?php echo $row4["nom_article"]."<br>","<br>"; ?></div>
<?php
}
}
?>
</div>
</body>
</html>