Prevent ability from adding a duplicate domain.

This commit is contained in:
Mark Crane 2012-08-12 12:45:10 +00:00
parent 648a30da5f
commit 2e60de8cd1
1 changed files with 24 additions and 16 deletions

View File

@ -75,6 +75,13 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//add or update the database //add or update the database
if ($_POST["persistformvar"] != "true") { if ($_POST["persistformvar"] != "true") {
if ($action == "add") { if ($action == "add") {
$sql = "select count(*) as num_rows from v_domains ";
$sql .= "where domain_name = '$domain_name' ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
$sql = "insert into v_domains "; $sql = "insert into v_domains ";
$sql .= "("; $sql .= "(";
$sql .= "domain_uuid, "; $sql .= "domain_uuid, ";
@ -90,6 +97,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$db->exec(check_sql($sql)); $db->exec(check_sql($sql));
unset($sql); unset($sql);
} }
}
}
if ($action == "update") { if ($action == "update") {
$sql = "update v_domains set "; $sql = "update v_domains set ";
@ -137,7 +146,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
foreach ($result as &$row) { foreach ($result as &$row) {
$domain_name = $row["domain_name"]; $domain_name = $row["domain_name"];
$domain_description = $row["domain_description"]; $domain_description = $row["domain_description"];
break; //limit to 1 row
} }
unset ($prep_statement); unset ($prep_statement);
} }