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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.