just doing an INSERT using mySQL which works fine…
mysql_query("INSERT INTO FLIGHTS_AVAILABLE
(aircraftID, aircraftType, maxSeats) VALUES('$theaircraftID', '$addType', '$maxCapacity' ) ")
or die(mysql_error());
echo '<p>';
echo "The following details were added into the database:";
echo "<hr>";
echo $theaircraftID . $addType . $maxCapacity;
This works fine, however I’ve looked online and whilst I have heard of a feature called IF NOT EXISTS, there are not very good explanations online about it’s use.
Is there anyway, I can run this query above, providing that if for example $theaircraftID = 10, and there is already a row in the database where the aircraftID = 10, then the query would not be run?
Thanks for any help you may be able to suggest,
Tom
Add a
UNIQUE INDEXon'FLIGHTS_AVAILABLE'.'aircraftID'. MySQL will block additionalINSERTs with the same value. Additionally you can useON DUPLICATE KEY EXISTSto run anUPDATEincase theINSERTgive aDUPLICATE KEYconstraint error.