简体   繁体   中英

How can I limit the number of registrants to an event?

I've set up a basic html/php submission form where people can register for our event, but need a way to replace the submission form webpage with one that reads something like "We have reached our registration limit" when we reach a certain number of submitted forms. Our database is MySQL (if that makes a difference) I've looked around on the web but people either say to count the entries by hand, or the ones that do have an automated system use CMS like drupal or joomla. Is it possible to setup an automated script that will do this?

$result = mysql_query("SELECT COUNT(*) FROM Users");
$row = mysql_fetch_row($result);
if ($row[0] > 50) echo 'We have reached our registration limit';

Before you insert a record, count ( SELECT COUNT(*) ) all the previous registrations. After that all you need to do is a simple if .

Remember, DBs queries are executed in sequential order.

You don't need nothing fancy, I'm not viewing your code, but you can make something like this:

your_file.php

<?

$count = mysql_fetch_array(mysql_query(" SELECT COUNT(*) FROM your_table "));

if ($count<10) {

   // your form code

}else{

  // your "full" message

}

?>

10 -> Max number of people to attend to that event!

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