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

@ -49,7 +49,7 @@ else {
$domain_description = check_str($_POST["domain_description"]); $domain_description = check_str($_POST["domain_description"]);
} }
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$msg = ''; $msg = '';
if ($action == "update") { if ($action == "update") {
@ -75,20 +75,29 @@ 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 = "insert into v_domains "; $sql = "select count(*) as num_rows from v_domains ";
$sql .= "("; $sql .= "where domain_name = '$domain_name' ";
$sql .= "domain_uuid, "; $prep_statement = $db->prepare($sql);
$sql .= "domain_name, "; if ($prep_statement) {
$sql .= "domain_description "; $prep_statement->execute();
$sql .= ")"; $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$sql .= "values "; if ($row['num_rows'] == 0) {
$sql .= "("; $sql = "insert into v_domains ";
$sql .= "'".uuid()."', "; $sql .= "(";
$sql .= "'$domain_name', "; $sql .= "domain_uuid, ";
$sql .= "'$domain_description' "; $sql .= "domain_name, ";
$sql .= ")"; $sql .= "domain_description ";
$db->exec(check_sql($sql)); $sql .= ")";
unset($sql); $sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'$domain_name', ";
$sql .= "'$domain_description' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
}
} }
if ($action == "update") { if ($action == "update") {
@ -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);
} }