This is a discussion on UPDATE or INSERT or both within the MySQL forums, part of the Database Server Software category; --> I have a simple table BoatTripID (int) (autoincrement) (key) TripTypeID (int) TripDate (date) An html form sends me the ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have a simple table BoatTripID (int) (autoincrement) (key) TripTypeID (int) TripDate (date) An html form sends me the data that I am going to put into a query. It will send me the TripTypeID and the TripDate. The data might already be in the table, or it might have been changed by the form. It also may already be in the database as a certain trip type, but the user wants to cancel the trip and delete the record. Is there a quick way to check for the existence of a record, make changes if necessary, leave the record unchanged if unchanged, and delete if necessary? I could do it with lots of queries and code, but I was wondering if there is some simpler way of doing this. |
| |||
| Kevin wrote: > I have a simple table > > BoatTripID (int) (autoincrement) (key) > TripTypeID (int) > TripDate (date) > > An html form sends me the data that I am going to put into a query. It > will send me the TripTypeID and the TripDate. I think the form did (or optionally did) show the data in the table. So you'd have to send the BoatTripID as well for existing records. > The data might already > be in the table, or it might have been changed by the form. It also > may already be in the database as a certain trip type, but the user > wants to cancel the trip and delete the record. You wouldn't know if the data was already in the table if you did not send unique data to check for. If, for instance, there can be only one trip on a day, you could make the date field unique (by adding a unique index to that field) > Is there a quick way to check for the existence of a record, make > changes if necessary, leave the record unchanged if unchanged, and > delete if necessary? I could do it with lots of queries and code, but > I was wondering if there is some simpler way of doing this. Look in the help for the INSERT command, especially the INSERT... ON DUPLICATE KEY UPDATE syntax. For this to work, you will need a unique field. It will never delete something, though Hope this helps, -- Willem Bogaerts Application smith Kratz B.V. http://www.kratz.nl/ |