You've got things out-of-order. You're trying to query the DB before you create your $sql.
(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:
PHP Code:
for($i = 0; $i > $people; $i++){
// $listhour = $listhour+1;
$newtimes = $listhour . " " . $listampm;
$listhour = $listhour+1;
// etc. . .
Speaking of your loop, it's always best not to do multiple queries inside loops. Instead, write your query and execute it only once:
PHP Code:
$sql = "INSERT INTO `tbl_name`( `col_1`,`col_2` ) ";
for( $i=0; $i < $max; $i++ ){
$sql_values[] = "VALUES( '$val_1','$val_2' ) ";
}
# concatenate VALUE clauses and append to SQL query
$sql .= implode( ',',$sql_values );
# *now* execute the query
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.
For any further help, we'd probably need to see more of your code.
Bookmarks