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
|
<?php
session_start();
$host = "localhost";
$dbName="xxxxx";
$user = "xxxx";
$password = "xxxxxxx";
//connexion
try{
$dsn = "mysql:host=$host;dbname=$dbName";
$options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8' );
$dbh = new PDO($dsn, $user, $password, $options);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Échec lors de la connexion : ' . $e->getMessage();
}
/* Traitement du formulaire de création de Topic */
if(isset($_SESSION['id'])) {
if(isset($_POST['tsubmit'])) {
if(isset($_POST['tsujet'],$_POST['tcontenu'])) {
$sujet = htmlspecialchars($_POST['tsujet']);
$contenu = htmlspecialchars($_POST['tcontenu']);
if(!empty($sujet) AND !empty($contenu)) {
if(strlen($sujet) <= 70) {
if(isset($_POST['tmail'])) {
$notif_mail = 1;
} else {
$notif_mail = 0;
}
$ins = $dbh->prepare('INSERT INTO f_t (id_createur, sujet, contenu, notif_createur, date_heure_creation) VALUES(?,?,?,?,NOW())');
$ins->execute(array($_SESSION['id'],$sujet,$contenu,$notif_mail));
$lastid = $dbh->lastInsertId();
if(isset($_FILES['miniature']) AND !empty($_FILES['miniature']['name'])) {
if(exif_imagetype($_FILES['miniature']['tmp_name']) == 2) {
$chemin = 'miniature/'.$lastid.'.jpg';
move_uploaded_file($_FILES['miniature']['tmp_name'], $chemin);
} else {
$message = 'Votre image doit être au format jpg';
}
}
} else {
$terror = "Votre sujet ne peut pas dépasser 70 caractères";
}
$message = 'Votre produit est mis en vente';
} else {
$terror = "Veuillez compléter tous les champs";
}
}
}
} else {
$terror = "Veuillez vous connecter pour poster un nouveau topic";
}
require('views/nouveau_topic.view.php'); /* Appel du fichier "vue" de notre page */
?> |
Partager