简体   繁体   中英

Check for value of a checkbox in database

I'm working on a from that sends a mass email to selected groups of participants (people registered for a program).

Form looks like this:

1) (checkbox) Program Name Start Date

2) (checkbox) Program Name Start Date

3) (checkbox) Program Name Start Date

4) (checkbox) Program Name Start Date

5) (checkbox) Program Name Start Date

Let's say you check all of them, but one of them (number 3 for instance) doen't have any participants registered for the program.

When the form is submitted, a MySQL error is thrown, and any program participants (in this case 4 & 5) won't get an email sent to them, and the user submitting the form is none the wiser.

<form id="email_form" name="email_form" action="email_broadcast_test.php" method="get">
<input name="pid[]" type="checkbox" class="eventCodeCheck" value="<?php echo $row_programs['eventcode']; ?>"/>
<input type="submit" value="Send Email" class="ButtonDefault" />

So I need to figure out and more importantly, learn and understand how to check if the program is empty and throw an alert to notify the user and not submit the form.

Another idea I had was to be able to check if the program was empty on page load, and disable the check box.

OR,

Throw an alert when the checkbox is checked notifying the user it is empty.

Thank you in advance.

You should not display the checkbox... to do that you need to add a WHERE clause in your MySQL query to only get the programs where someone is actually registered.

No sense in displaying a checkbox if you can't use it.

If you post your current query and a little about your db then I could help you better.

Your query could be:

SELECT eventcode, eventdesc, date_format(date, '%m/%d/%Y') as format_date 
FROM camps_events WHERE reg_status!= 'Archived' 
AND eventcode IN (SELECT DISTINCT eventcode FROM registrations) 
".getAllowedPrograms()." ORDER BY eventdesc";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM