I am trying to run an query using php into a database, I need to check if the customers address
is already exists then do not insert, but if not exists then insert into table, I have based it around the following:
$query = "INSERT INTO address(id,address_type)
SELECT('1111','bill')FROM DUAL
WHERE NOT EXISTS
(SELECT * FROM address
WHERE id='1111' AND address_type='bill')";
$n = mysql_query($query, $connect ) or die(mysql_error());
This allows me to insert just the id
but not the address_type
.
I will have the same id
for both bill
& ship
addresses making a unique field not possible.
I have about 8 fields to insert, what am I doing wrong?