Commit 3c20f042 authored by David Morley's avatar David Morley

check db for existing data on add

parent 25d0b421
<?php <?php
include('config.php'); include('config.php');
if (!$_POST['url']){
echo "no url given";
die;
}
if (!$_POST['email']){
echo "no email given";
die;
}
if (!$_POST['domain']){
echo "no pod domain given";
die;
}
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass"); $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die("Error in connection: " . pg_last_error());
} }
$sql = "SELECT domain,pingdomurl FROM pods";
$result = pg_query($dbh, $sql);
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
while ($row = pg_fetch_array($result)) {
if ($row["domain"] == $_POST['domain']) {
echo "domain already exists";die;
}
if ($row["pingdomurl"] == $_POST['url']) {
echo "pingdom report already exists";die;
}
}
$pingdomurl = pg_escape_string($_POST['url']); $pingdomurl = pg_escape_string($_POST['url']);
$domain = pg_escape_string($_POST['domain']); $domain = pg_escape_string($_POST['domain']);
......
...@@ -19,7 +19,7 @@ od last updated from the main Diaspora code.">?</a></th> ...@@ -19,7 +19,7 @@ od last updated from the main Diaspora code.">?</a></th>
if (!$dbh) { if (!$dbh) {
die("Error in connection: " . pg_last_error()); die("Error in connection: " . pg_last_error());
} }
$sql = "SELECT * FROM pods"; $sql = "SELECT * FROM pods WHERE hidden <> 'no'";
$result = pg_query($dbh, $sql); $result = pg_query($dbh, $sql);
if (!$result) { if (!$result) {
die("Error in SQL query: " . pg_last_error()); die("Error in SQL query: " . pg_last_error());
......
...@@ -2,7 +2,7 @@ CREATE TABLE pods ( ...@@ -2,7 +2,7 @@ CREATE TABLE pods (
id serial8 UNIQUE PRIMARY KEY, id serial8 UNIQUE PRIMARY KEY,
domain text UNIQUE NOT NULL, domain text UNIQUE NOT NULL,
whois text, whois text,
hidden text DEFAULT 'no', hidden text DEFAULT 'yes',
ip cidr, ip cidr,
ptr text, ptr text,
email text, email text,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment