The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The form and inserting days works fine, but a user should be able to change the amount of days for a trip on form2
So if a trip currently is currently 4 days and a user wants to add 3 days to make it 7 then I would need to have the first 4 days updated and the last 3 days inserted, since days 1 to 4 are already in the database.

By making use of MySQL's REPLACE command, which is basically a "INSERT if it doesn't exist, otherwise UPDATE the existing entry", you should be able to increase a trip's length by just REPLACE'ing a number of 'day' entries equal to the new trip length. Shortening a trip should be fairly straightforward too, as you can just DELETE where 'day' is greater that the number of days specified for the trip.

> What I don't get is why the id gets changed from 3 to 4. I've tried using
> a null for the id and gotten the same results. I have to do an extra
> SELECT id from ffc_initial where emailaddr='promote@webmarquee.com' to
> maintain the same id. This sort of defeats the purpose of have a REPLACE
> when you care to maintain an external key. Anybody know why this is?
[...]
> I presume REPLACE works by seeing if your new entry conflicts with any of
> the unique fields in your previous entries and replaces the old one if it
> does. INSERT defers to the pre-existing entry while REPLACE defers to the
> one you are asking to add.

Replace _deletes_ the original entry and then creates a new one. This is why
the "auto_increment"ed counter goes to 4, rather than remaining at 3.

'insert' always creates a new entry. (except it if fails due to a duplicate
key).
'replace' always removes the existing entry and then creates a new entry
'update' allows you to change an existing entry

Think of the consequences if the primary key of the table in the example is a foreign key in a related table. Not pretty!

As to your specific problem, Mr Bond, I think it might be solved if you were to do away with the (I presume) unnecessary column "id" in table "days". Instead if your primary key where defined as the composite of the columns "tid, day" then I think your replace would work.