-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddOption.php
More file actions
47 lines (39 loc) · 1.19 KB
/
addOption.php
File metadata and controls
47 lines (39 loc) · 1.19 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
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<h1>Add Options!</h1>
<?php
$option = $_POST['option'];
$id=$_POST['id'];
if ($id and $option) {
# This function reads your DATABASE_URL config var and returns a connection
# string suitable for pg_connect. Put this in your app.
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1); # <- you may want to add sslmode=require there too
}
# Here we establish the connection. Yes, that's all.
$db = pg_connect(pg_connection_string_from_database_url());
if (!$id or !$option) {
echo "Enter an option and id";
} else {
$query="INSERT INTO num".$id. " VALUES ( '".$option."', 0);";
$result=pg_query($db,$query);
echo pg_last_error();
}
pg_close($db);
}
if(isset($_POST))
{?>
<form method="POST" action="addOption.php">
ID <input type="text" name="id"></input><br/>
Option <input type="text" name="option"></input><br/>
<input type="submit" name="submit" value="Add Option"></input>
</form>
<?}
if ($id and $option) {
echo "<h2>".$option." Added</h2>";
}
?>
</html>