Reputation: 13
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?
Upvotes: 1
Views: 2692
Reputation: 16269
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!
Upvotes: 0
Reputation: 16533
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.
Upvotes: 0
Reputation: 6363
$result = mysql_query("SELECT COUNT(*) FROM Users");
$row = mysql_fetch_row($result);
if ($row[0] > 50) echo 'We have reached our registration limit';
Upvotes: 5