-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.php
31 lines (24 loc) · 945 Bytes
/
conn.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
<?php
include './db_connection.php'; //includes connection to database
$value = ""; //initially set the value coming to the api as empty
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$value = test_input($_GET["value"]); //accept the value from the reqpuest, the requestion was suffixed ?value
$sql = "INSERT INTO data_table (value) VALUES ('" . $value . "')"; //insert the value gotten into the table "data_table" in the database
//check if the insertion is successful
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
} else {
echo "No data posted with HTTP GET."; //if request is not get
}
//this function is used to sanitize user request
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}