Skip to content
Snippets Groups Projects
Commit b7c9fce4 authored by MENOUER SARAH's avatar MENOUER SARAH
Browse files

rendu

parent bc4a86ed
No related merge requests found
<?php
// fichier appelé par l'appel AJAX pour charger les recettes dans le fichier principal
include_once 'form.php';
try {
$pdo = new PDO('sqlite:' . dirname(__FILE__) . '/database.db');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->query('CREATE TABLE IF NOT EXISTS recipes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL
)');
$comment = $pdo->query('SELECT * FROM recipes')
$recipe = $pdo->query('SELECT * FROM recipe')
->fetchAll();
echo json_decode($comment);
echo json_decode($recipe);
} catch (Exception $exception) {
var_dump($exception->getMessage());
}
No preview for this file type
<?php
// Fichier appelé pour insérer les recettes dans la base de données
// Fichier appelé pour insérer les recipesaires dans la base de données
if(isset($_POST['nomRecette']) && isset($_POST['content'])){
$nomRecette = htmlspecialchars($_POST['nomRecette']);
$content = htmlspecialchars($_POST['content']);
}
try {
$pdo = new PDO('sqlite:' . dirname(__FILE__) . '/database.db');
$pdo = new PDO('sqlite:' .dirname(__FILE__) . '/database.db');
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->query('CREATE TABLE IF NOT EXISTS recipes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL
)');
$pdo->query('INSERT INTO recipes (username, content)
VALUES ("' . $_POST["username"] . '", "' . $_POST["username"] . '")
');
} catch (Exception $exception) {
var_dump($exception->getMessage());
}
$pdo->query(
'CREATE TABLE IF NOT EXISTS recipes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nomRecette VARCHAR(150) NOT NULL,
content TEXT NOT NULL
)'
);
if (isset($nomRecette) && isset($content)){
$statement = $pdo->prepare(
'INSERT INTO recipes (nomRecette, content)
VALUES (:nomRecette, :content)');
$statement ->bindvalue('nomRecette',$nomRecette ,PDO::PARAM_STR);
$statement ->bindvalue('content',$content ,PDO::PARAM_STR);
$statement -> execute();
header("location:index.php");
}
}
catch (Exception $exception) {
var_dump($exception->getMessage());
}
<!doctype html>
<html>
<head>
<title>Document</title>
<link rel="stylesheet" href="style.css"/>
<script src="script.js"></script>
</head>
<body>
<nav>
<form>
<input type="text">
<input type="text">
<input type="submit" value="Valider">
</form>
<button>
Afficher les recettes
</button>
<section id="recipes">
<article>
<p>Titre</p>
<p>Content</p>
</article>
<article>
<p>Titre</p>
<p>Content</p>
</article>
<article>
<p>Titre</p>
<p>Content</p>
</article>
</section>
</nav>
</body>
<head>
<title>exam</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<section>
<form id="eRecette" method="post" action="form.php">
<div>
<label for="nomRecette">NomRecette</label>
<input id="nomRecette" type="text" placeholder="le nom de la recette" id="nomRecette" class="input" name="nomRecette" />
</div>
<div>
<label for="content"></label>
<input id="content" type="text" name="content" placeholder="Content">
</div>
<input id="btn_submit" type="submit" name="btn_submit" value="Valider">
</form>
<input id="btn_comment" name="btn_comment" type="button" value="Afficher les recettes"/>
<section id="recipes">
<article>
<p>Titre</p>
<p>Content</p>
</article>
<article>
<p>Titre</p>
<p>Content</p>
</article>
<article>
<p>Titre</p>
<p>Content</p>
</article>
</section>
<!-- <section id="recipes">
<h1>Affichage des recettes :</h1>
<php
$recette = $pdo->query('SELECT * FROM comment ORDER BY id DESC')->fetchAll();
?>
<article>
<p>Title : <php echo $recipe['nomRecette'];?></p>
<p>Content : <php echo $recipe['content']; ?></p>
</article>
<article>
<p>Title : <php echo $recipe['nomRecette'];?></p>
<p>Content : <php echo $recipe['content']; ?></p>
</article>
<article>
<p>Title : <php echo $recipe['nomRecette'];?></p>
<p>Content : <php echo $recipe['content']; ?></p>
</article>
</section> -->
</section>
<script src="script.js"></script>
</body>
</html>
\ No newline at end of file
......@@ -4,4 +4,32 @@ const button = document.querySelector('button');
button.addEventListener('click', () => {
})
\ No newline at end of file
})
var click = document.getElementById("btn_comment");
fetch('http://localhost/exam_substitution_l2s4a2021-main/api.php')
.then(comment =>{
console.log(comment)
if (comment.ok) {
comment.json()
.then(data => {
data.forEach(dataComments => {
username.innerText = `Utilisateur : ${dataComments.username}`
content.innerText = `Comment : ${dataComments.username.content}`
})
} )
}
}
)
.catch(error => {
console.log(error)
}
)
\ No newline at end of file
......@@ -8,4 +8,16 @@
border: 1px solid black;
padding: 20px;
border-radius: 5px;
}
@media (max-width: 800px) {
#recipes {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 480px) {
#recipes {
grid-template-columns: repeat(1, 1fr);
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment