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.

help using FOR then adding to data-base

My form consists of a "select amount of people" select menu,
a select menu to select the hour,
and a date select menu,

What is meant to happen:
the user selects how many people is meant to be booked in and which hour of the day they are booking in, each person gets booked in for 1 hour each,
so if they were booking in 3 people that is 3 hours they are booking in for, from the hour of the day selected, so if someone books in 3 people at 3pm that books in from 3 tell 6 so (3pm 4pm 5pm)

so using a for statement i grab these times to prepare them to be added to the mysql data-base to make these times booked so no one else can book these times on this date. So how would i add these to a mysql data-base using a for statement?

here is my code:
compdate is the day of the month then the month completed how it should be,
i made the hour -1 so when it adds it adds the correct time because when it runs the for tag its always +1

Obviously this looks like it would work but dosent because it wont run the mysql correctly and insert it to the data-base, a bit of sloppy code which i need help, so it adds all the times to the mysql that have been booked in.

Apologies if this is a MySQL question i couldn't figure out if it was a MySQL rather than a php because it uses the for tag i leaned more to that php side of things or at least that's how it seems to me

(Incidentally, this means that you should be seeing an error. Make sure you have error reporting enabled if you don't.

(There are lots of undefined variables in the code you posted. I'm going to assume that most of them are defined elsewhere, but you should definitely double-check. When posting code excerpts like this, it's always a good idea to let people know where you did indeed define a var somewhere else, so no one wastes time suggesting you fix something that might not be broken.)

You should not use the mysql_* functions. They are deprecated. You should look into mysqli or PDO.

I'm not sure what you're trying to do with $listhour. If it's just the initial iteration of the loop that you're trying to fix, simply increment it after you write your sql:

Just from looking at the value you're preparing for your DB, I would suspect that there's a better way to design your DB table. That's a separate issue, of course, but if you're interested you can post your DB schema.