blesseld Posted December 22, 2009 Share Posted December 22, 2009 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 Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/ Share on other sites More sharing options...
rajivgonsalves Posted December 22, 2009 Share Posted December 22, 2009 I recommend you use mysql_num_rows instead http://php.net/manual/en/function.mysql-num-rows.php Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982395 Share on other sites More sharing options...
ChemicalBliss Posted December 22, 2009 Share Posted December 22, 2009 Just use a mysql count query. http://dev.mysql.com/doc/refman/5.1/en/counting-rows.html eg: $query = "SELECT COUNT(*) FROM `adccmemebers`"; $number_of_users = mysql_result(mysql_query($query),0); -CB- Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982403 Share on other sites More sharing options...
blesseld Posted December 22, 2009 Author Share Posted December 22, 2009 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 Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982472 Share on other sites More sharing options...
.josh Posted December 22, 2009 Share Posted December 22, 2009 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 { Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982473 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 $sql = "SELECT COUNT(*) FROM 'adccmemebers'"; $sql_query = mysql_query($sql); if ($sql_query = mysql_query($sql)) { $number_of_users = mysql_result($sql_query,[b]0[/b]); } else { // The query didnt work // } Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982476 Share on other sites More sharing options...
blesseld Posted December 22, 2009 Author Share Posted December 22, 2009 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. Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982488 Share on other sites More sharing options...
rajivgonsalves Posted December 22, 2009 Share Posted December 22, 2009 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 { Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982502 Share on other sites More sharing options...
blesseld Posted December 22, 2009 Author Share Posted December 22, 2009 Thanks All, I don't know how I over looked the misspelling with single quotes, working now. Link to comment https://forums.phpfreaks.com/topic/186035-limit-number-of-users-signup-count-db-entries/#findComment-982517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.