· 4 years ago · Dec 05, 2020, 08:16 PM
1<?php
2include("db.php");
3
4header("Access-Control-Allow-Origin: http://localhost:8080");
5
6
7// extract data form POST
8// $prenom = htmlspecialchars($_POST['prenom']);
9// $nom = htmlspecialchars($_POST['nom']);
10// $message = htmlspecialchars($_POST['message']);
11
12$prenom = "tesdddt";
13$nom = "tst name";
14$message = "teeeeeesttttt";
15
16
17try {
18 //create table if not exist
19 $pdo->exec(
20 'CREATE TABLE IF NOT EXISTS msg (
21 id INTEGER PRIMARY KEY AUTOINCREMENT,
22 prenom VARCHAR(20) NOT NULL,
23 nom VARCHAR(20) NOT NULL,
24 message TEXT NOT NULL
25 )'
26 );
27
28 //insertion des données
29 $statement = $pdo->prepare('
30 INSERT INTO msg (prenom, nom, message)
31 VALUES (:prenom, :nom, :message)
32 ');
33
34 //bind
35 $statement->bindValue("prenom", $prenom, PDO::PARAM_STR);
36 $statement->bindValue("nom", $nom, PDO::PARAM_STR);
37 $statement->bindValue("message", $message, PDO::PARAM_STR);
38 $statement->execute();
39
40 //return response
41 http_response_code(200);
42} catch (PDOException $exception) {
43 http_response_code(400);
44}
45
46
47
48
49
50
51