add.php 1.18 KB
Newer Older
David Morley's avatar
David Morley committed
1 2
<?php
 include('config.php');
3 4 5 6 7 8 9 10 11 12 13 14 15
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;
}

David Morley's avatar
David Morley committed
16 17 18 19
 $dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
     if (!$dbh) {
         die("Error in connection: " . pg_last_error());
     }
20 21 22 23 24 25 26 27 28 29 30 31 32 33
 $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;
}
 }

David Morley's avatar
David Morley committed
34
    
35
     $pingdomurl = pg_escape_string($_POST['url']);
David Morley's avatar
David Morley committed
36 37 38
     $domain = pg_escape_string($_POST['domain']);
     $email = pg_escape_string($_POST['email']);
    
39
     $sql = "INSERT INTO pods (domain, pingdomurl, email) VALUES('$domain', '$pingdomurl', '$email')";
David Morley's avatar
David Morley committed
40 41 42 43 44 45 46 47 48 49 50 51
     $result = pg_query($dbh, $sql);
     if (!$result) {
         die("Error in SQL query: " . pg_last_error());
     }
    
     echo "Data successfully inserted!";
    
     pg_free_result($result);
    
     pg_close($dbh);

?>