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?
+4
A:
$result = mysql_query("SELECT COUNT(*) FROM Users");
$row = mysql_fetch_row($result);
if ($row[0] > 50) echo 'We have reached our registration limit';
Lotus Notes
2010-06-02 21:28:13
thanks! this might be a supremely basic question, but where should i past this on the page? As Ben said the queries are executed in sequential order, so should i paste this at the top?
2010-06-02 21:55:55
You'd want to do it before the registration query occurs, so that you can halt the registration attempt and print the error message.
Lotus Notes
2010-06-02 22:21:18
Also, please consider clicking the check mark if you found this answer helpful. Having a high accept rate will make people more willing to answer your questions.
Lotus Notes
2010-06-03 19:02:25
check has been marked! wish i could upvote it but i dont have enough rep
2010-06-03 20:44:45
A:
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.
Ben
2010-06-02 21:29:06
A:
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!
Zuul
2010-06-02 21:31:36