-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate.php
More file actions
49 lines (35 loc) · 1.14 KB
/
create.php
File metadata and controls
49 lines (35 loc) · 1.14 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
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// $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);
$name = $_POST['name'];
$value = $_POST['value'];
$create_table = "
CREATE TABLE IF NOT EXISTS iotUSER (
name VARCHAR(30) PRIMARY KEY,
value INT(100) NOT NULL
);";
if ($conn->exec($create_table)) {
echo "Table Created";
}
if($conn->exec("INSERT INTO $dbtable (name, value) VALUES ('$name', '$value')")){
header("location:./?name=$name");
}
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>