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
|
<?php
if(isset($_POST['titre'])&& isset($_POST['description']) && isset($_POST['age']) && isset($_POST['origine']) && isset ($_POST['num']) && isset($_POST['ville']) && isset($_POST['cp']) && isset($_POST['statut']) && isset ($_FILES['photo1'])) {
if(isset($_FILES['photo1']) && $_FILES['photo1']['error']==0) { // Inscription de la photo uploadé dans le dossier bouquin
move_uploaded_file($_FILES['photo1']['tmp_name'],
'./md/'.basename($_FILES['photo1']['name']));
echo 'L\'envoi a bien été effectué';
}
try{ // Connexion à la BDD
$bdd=new PDO('mysql:host=wwwwwww;dbname=,nnnnnn', 'nnnnnnnnnnn','nnnnnnnnnn');
}
catch(Exception $e){
die ('Erreur:'.$e->getMessage());
}
// Insertion des données envoyées par l'internaute grâce à une requête préparée
$stockage='http://nnnnnnnnnn.fr/nnnnnnn/md/'.$_FILES['photo1']['name'].'';
$insertion=$bdd->prepare('INSERT INTO annonces(titre, description, age, origine, num, ville, cp, statut, photo1) VALUES (:titre, :description, :age, :origine, :num, :ville, :cp, :statut, :photo1)');
$insertion->execute(array(
'titre' => $_POST['titre'],
'description' => $_POST['description'],
'age' => $_POST['age'],
'origine' => $_POST['origine'],
'num' => $_POST['num'],
'ville' => $_POST['ville'],
'cp' => $_POST['cp'],
'statut' => $_POST['statut'],
'photo1' => $stockage
));
if($insertion==true) {
echo '<p> Les données ont bien été enregistrées</p>';
}
else {
echo 'Erreur dans l\'enregistrement des données </p>';
}
$insertion->closeCursor(); // déconnexion
}
?> |
Partager