-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathset.php
More file actions
36 lines (29 loc) · 1.02 KB
/
set.php
File metadata and controls
36 lines (29 loc) · 1.02 KB
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
<?php
// CONNECTING TO THE DATABASE
// $servername = "localhost";
// $username = "root";
// $password = "";
// $dbname = "iot";
// $dbtable = "iotUSER";
$url = getenv('JAWSDB_URL');
$dbparts = parse_url($url);
$servername = $dbparts['host'];
$username = $dbparts['user'];
$password = $dbparts['pass'];
$dbname = ltrim($dbparts['path'],'/');
$dbtable = "iotUSER";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_GET['name']) && isset($_GET['value'])){
$name = $_GET['name'];
$value = $_GET['value'];
$db_response = $conn->prepare("UPDATE $dbtable SET value = $value WHERE name = '$name' ")->execute();
echo "Value set to $value";
header("location:./?name=$name");
}
}
catch(PDOException $e){
echo "Connection failed: " . $e->getMessage();
}
?>