Jump to content

What's wrong with my code?


ivytony

Recommended Posts

The code I wrote is to save a domain name in the database. Before storing the domain, the code will check if it already existed. On the HTML page, there's a checkbox that allows duplicate domains, otherwise only one unique domain is allowed in the database.

 

Firstly, I created this function:

 

<?php
function duplicates($domain) { //check if the merchant already exists by looking at domain
	global $db;

	$n = $db->get_var("SELECT count(*) FROM domains WHERE domain = '$domain'");  //get_var is a function
	return $n;
}
?>

 

Below is to check the domain and store it:

<?php 
               $isduplicate = $_POST["duplicatedomain"];   // get the value of checkbox that allows duplicate domain
         if(duplicates($domain) > 0){   //if domain exists already
           
			if($isduplicate == 1){   //allows duplicate domain
			add_domain();   //a function to store the domain
             header("Location: admin_domains.php");
			}
			else{
		echo 'this domain already exists';
     	                exit;
			}
	 }
	 else{
      add_domain();
     header("Location: admin_domains.php");
	 }
?>

 

My problem is: no matter if the domain existed in database or not, it always stores the domain. I cannot figure out what's wrong.

Link to comment
https://forums.phpfreaks.com/topic/96760-whats-wrong-with-my-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.