I'm pretty new to php and mysql so bear with me while I try to explain what I'm going for.
I have an online form that is taking information and placing it into a MYSQL database. That function works perfectly, but now I'm to the point where I want to cut down on duplicate entries as much as possible.
Our employees will be entering Customer Name, billing address, and shipping address to the db. Some customers have multiple billing addresses and shipping addresses though. What I'd like to do is make it so that if any one of those 3 is a new entry then the record is saved but if all 3 are duplicates it does not get inserted into the database. I was hoping something like this would do the trick:
$cn = $_POST[CustomerName];
$ba = $_POST[BillingAddress];
$sa = $_POST[ShippingAddress];
$custname = mysqli_query("SELECT DISTINCT customerName FROM customer WHERE customerName LIKE '$cn'");
$billaddress = mysqli_query("SELECT DISTINCT billingaddress FROM customer WHERE billingaddress LIKE '$ba'");
$shipaddress = mysqli_query("SELECT DISTINCT shippingaddress FROM customer WHERE shippingaddress LIKE '$sa'");
if ($custname != $_POST[CustomerName] OR $billaddress != $_POST[BillingAddress] OR $shipaddress != $_POST[ShippingAddress])
{
mysqli_query($con,"INSERT INTO customer(customerName, billingaddress, shippingaddress)
VALUES
('$_POST[CustomerName]','$_POST[BillingAddress]','$_POST[ShippingAddress]')");
}
Unfortunately, this still adds the record when all three parameters are duplicates. Anythoughts on why that would be happening, or any suggestions on how to get my desired results a little easier?
I've tried making the customer name field unique, but when that's the case it drops the entire record. If I'm understanding correctly, the primary key / unique method won't be able to be used for my issue. That is likely my inexperience talking though, so if anyone could help I'd appreciate it greatly.
EDIT: I thought I'd also mention I've tried using mysql_real_escape_string methods and the array return method to no avail.
The table dafinition is this:
**customer**
idcustomer (primary key, auto-increment)
customerName
billingaddress
shippingaddress