I have a MYSQL query question that I think will be fairly simple to answer but I'm just not sure of the proper syntax to use. I'm looking to insert values into a table that has a UserID as the primary key, however, I don't want the values to be inserted if the UserID has more than 3 records associated with it. Basically, something like:
INSERT INTO AutosForSale (UserID, Year, Make, Model, Model_Description, Price, City, State, Zip, Mileage, Exterior_Color, Interior_Color, Description)
WHERE (SELECT Count(*) FROM AutosForSale WHERE UserID = '$userid') < 3";
I'm using PHP so the $ values are inputs I'm getting from my user.
Can someone please recommend the proper way to do this?? My code posted above does not work correctly.....Thanks!