I am trying to make a form that will keep a record of 1) all the people who have attended a sports practice,2) what activity they completed and 3) the date they completed it.
Right now I have the list of people populated from a user table in my database.
CREATE TABLE tbl_user (
userID int(11) NOT NULL auto_increment,
firstName varchar(50) default NULL,
lastName varchar(50) default NULL,
email varchar(50) default NULL,
username varchar(50) default NULL,
password varchar(50) default NULL,
usergroup varchar(50) default NULL,
PRIMARY KEY (userID),
KEY userID (userID)
) TYPE=MyISAM AUTO_INCREMENT=54 ;
I have another table which lists the type of activity and date of the practice:
CREATE TABLE attendancelist (
userID int(11) NOT NULL auto_increment,
firstName varchar(50) default NULL,
lastName varchar(50) default NULL,
activity varchar(50) default NULL,
dateday int(11) default NULL,
datemonth text,
password varchar(50) default NULL,
usergroup varchar(50) default NULL,
PRIMARY KEY (userID),
KEY userID (userID)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
Question one: are the database tables okay? Is there anything you might do differently?
Question two: Okay, so I have constructed the form.
Right now I am pulling the names for the userlist from the user table in the database and then displaying them in the form. Beside the names I have created three checkboxes so that the person taking attendance can select which activity they've completed. I've used checkboxes instead of drop down to make data entry more speedy.
So, the form looks like this:
Joe James []run []walk []play
Gee Whiz []run []walk []play
etc....
Question three: Is the above a reasonable way to handle this or would you do it differently?
The code for the form is below.
<?php do { ?>
<tr valign="top">
<td height="30"><?php echo $row_userlist['firstName']; ?> <?php echo $row_userlist['lastName']; ?> <input name="firstName" type="hidden" id="firstName" value="<?php echo $row_userlist['firstName']; ?>">
<input name="lastName" type="hidden" id="lastName" value="<?php echo $row_userlist['lastName']; ?>"></td>
<td>
<table width="200">
<tr>
<td width="67"><label>
<input name="walk" type="checkbox" id="walk" value="checkbox">
walk</label></td>
<td width="63"><input name="run" type="checkbox" id="run" value="checkbox">
run</td>
<td width="54"><input name="play" type="checkbox" id="play" value="checkbox">
play</td>
</tr>
</table></td>
</tr>
<?php } while ($row_userlist = mysql_fetch_assoc($userlist)); ?>
</table>
<input type="submit" name="Submit" value="Submit">
</form>
Question four: The problem is when I do the insert I'd like each user who is selected as having attended the practice to show up in the database table. But right now only the last name in the list is inserted. Why is this happening?
Is it possible to write an insert statement that allows data collected from one form to go into multiple rows? If so, how would you write an sql insert statement to insert the data from this form so that each user appears in a separate row in the database table? Or would you set up the form entirely differently?
Thanks for your help
Siobhan