Jump to content

Limit number of users signup, count db entries


blesseld

Recommended Posts

Hey,

 

I Simply am trying to limit the amount of people that can sign up.... 

Need a bit of help with getting this to work, I basically want to say if there are 30 users then show my error "Sorry we have reached our limit"

 

    $result = mysql_query("SELECT (*) FROM adccmembers WHERE user='$user'");
    while ($row = mysql_fetch_array($result)) {
        if ($row['30']) {
        	$sorry = "<div id=\"warning-box\"><p class=\"main-text\"><span style=\"color:#ff0000;\">Error</span>: Sorry, There are no more spots available.<br /><br /></p></div>";
        } else {
        	echo "";
        }
    }

 

I know this is wrong,  COuld anyone help me out.  I;ve tried alot and i continue to be able to sign up.

 

Thanks

Hey Guys,

 

Thanks

 

Heres what I tried,

 

    if ($query = "SELECT COUNT(*) FROM 'adccmemebers'") {
        $number_of_users = mysql_result(mysql_query($query), 10);
        $sorry = "<div id=\"warning-box\"><p class=\"main-text\"><span style=\"color:#ff0000;\">Error</span>: Sorry, There are no more spots available.<br /><br /></p></div>";
    } else {

 

it works,  However it says its not valid

 

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/affiliat/public_html/crash-course/ad-member-signup.php on line 89

 

is this just syntax?  like missing somthing to make it valid?

 

Thanks in advance

 

looks like your table name is typoed.  Also, in your mysql_result, for some reason you changed 0 to 10.  that 2nd argument represents which array element (column).  Since you are only querying for 1 column (the count), it needs to stay 0. Also, in your condition ,you are simply assigning a string to a variable, which will always be true.

 

$query = "SELECT COUNT(*) FROM 'adccmembers'";
$number_of_users = mysql_result(mysql_query($query), 0);
if ($number_of_users > 30) {
        $sorry = "<div id=\"warning-box\"><p class=\"main-text\"><span style=\"color:#ff0000;\">Error</span>: Sorry, There are no more spots available.<br /><br /></p></div>";
    } else {

looks like your table name is typoed.  Also, in your mysql_result, for some reason you changed 0 to 10.  that 2nd argument represents which array element (column).  Since you are only querying for 1 column (the count), it needs to stay 0. Also, in your condition ,you are simply assigning a string to a variable, which will always be true.

 

$query = "SELECT COUNT(*) FROM 'adccmembers'";
$number_of_users = mysql_result(mysql_query($query), 0);
if ($number_of_users > 30) {
        $sorry = "<div id=\"warning-box\"><p class=\"main-text\"><span style=\"color:#ff0000;\">Error</span>: Sorry, There are no more spots available.<br /><br /></p></div>";
    } else {

 

Tried this and didn't work,  I have not been able to get it to work when it's "0"  it still creates a user account successfully.

your code should be, you cannot put your table name in single quotes as CV pointed out earlier

 

$query = "SELECT COUNT(*) FROM `adccmembers`";
$number_of_users = mysql_result(mysql_query($query), 0);
if ($number_of_users > 30) {
        $sorry = "<div id=\"warning-box\"><p class=\"main-text\"><span style=\"color:#ff0000;\">Error</span>: Sorry, There are no more spots available.<br /><br /></p></div>";
    } else {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.