karatekid36 Posted June 21, 2007 Share Posted June 21, 2007 This form will have infinite amount of users loaded into for when we need to take attendance at meetings. How can you validate could for each of these radio groups when you are unsure of how many there will be because the amount of members can grow and shrink with time? Once this is validated, I would like to Insert the user id, member id , and attendance into a table. I do not yet understand how to validate this code and create an insert sql statement that will take into account that in week it may have 100 members but next time it may have 200, for example. Any help would be great. Thanks. <?php // Begin the page now. $page_title = 'Brothers Of Psi Beta'; $query = mysql_query("SELECT * FROM brothers WHERE user_id='$user_id'"); $row = mysql_fetch_assoc($query); if ($row['admin'] == 'admin'){ include ('./includes/header_admin.html'); } else { include ('./includes/header.html'); } // Page header. echo '<h1 id="mainhead">Attendance</h1>'; // Make the query. $query = "SELECT user_id, CONCAT_WS(', ', last_name, first_name) AS name FROM brothers WHERE status =\"Undergraduate\" ORDER BY last_name, first_name ASC"; $result = mysql_query ($query); // Run the query. if (!$result) { echo "The Query: $query Produced the error: ".mysql_error(); exit; } // Table header. echo '<form action="take_attend.php" method="post"><table align="center" cellspacing="0" cellpadding="3"> <tr> <td align="left"><b>Brother</a></b></td> <td align="left"><b>Attendance</a></b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the background color. while ($row = mysql_fetch_assoc($result)) {//mysql_fetch_assoc is identical to mysql_fetch_array(resultresource, MYSQL_ASSOC but with less typing $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['name'] . '</td> <td align="left">Present <input type ="radio" name="attend['.$row['user_id'].']" value="Present" /> Excused <input type ="radio" name="attend['.$row['user_id'].']" value="Excused" /> Unexcused <input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" /></td> </tr> '; } echo '</table> <p><input type="submit" name="submit" value="Take attendance" /></p> <input type="hidden" name="submitted" value="TRUE" />'; mysql_free_result ($result); // Free up the resources. mysql_close(); // Close the database connection. include ('includes/footer.html'); // Include the HTML footer. ?> Link to comment https://forums.phpfreaks.com/topic/56600-how-would-you-validate-a-form-like-this/ Share on other sites More sharing options...
Renlok Posted June 21, 2007 Share Posted June 21, 2007 i dont understand what you need validating Link to comment https://forums.phpfreaks.com/topic/56600-how-would-you-validate-a-form-like-this/#findComment-279545 Share on other sites More sharing options...
trecool999 Posted June 21, 2007 Share Posted June 21, 2007 You're not being very clear on what you want done... Link to comment https://forums.phpfreaks.com/topic/56600-how-would-you-validate-a-form-like-this/#findComment-279548 Share on other sites More sharing options...
karatekid36 Posted June 21, 2007 Author Share Posted June 21, 2007 I apoligize. Basically, I want to make sure that all the radio groups have a value selected, and then from there, I would like the proper values inserted into the table. Link to comment https://forums.phpfreaks.com/topic/56600-how-would-you-validate-a-form-like-this/#findComment-279551 Share on other sites More sharing options...
thefortrees Posted June 21, 2007 Share Posted June 21, 2007 Create a table that stores the 'checked' values and that is linked to each user with some sort of id. Then, in your HTML code after your query, you could do something like this while ($row = mysql_fetch_assoc($result)) {//mysql_fetch_assoc is identical to mysql_fetch_array(resultresource, MYSQL_ASSOC but with less typing $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['name'] . '</td> <td align="left">Present <input type ="radio" name="attend['.$row['user_id'].']" value="Present" checked="' . if ( $row['checked'] == "Present") echo 'checked'; .'">> Excused <input type ="radio" name="attend['.$row['user_id'].']" value="Excused" checked=' . if ( $row['checked'] == "Excused") echo 'checked';/> Unexcused <input type ="radio" name="attend['.$row['user_id'].']" value="Unexcused" checked=' . if ( $row['checked'] == "Unexcused") echo 'checked';/></td> </tr> '; } Link to comment https://forums.phpfreaks.com/topic/56600-how-would-you-validate-a-form-like-this/#findComment-279567 Share on other sites More sharing options...
karatekid36 Posted June 21, 2007 Author Share Posted June 21, 2007 But, I would like the values chosen to go directly to my attendance table. Link to comment https://forums.phpfreaks.com/topic/56600-how-would-you-validate-a-form-like-this/#findComment-279619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.