PHP/MySQLi: How can I compare Operators in IF statement using variables from two tables

I have a basic <form> wherein administrators can add users into the database.  I would like to add an IF statement prior to the <form> so that IF the current number of uses has not exceeded the maximum number of users allowed for that account, the form will be displayed (and show how many users are remaining).  Conversely, IF the maximum has been exceed, print/echo a message to the admin stating the maximum has been exceeded and to request more (in place of the form).

There are two tables in use:

users
user_id

company_information
max_records

Here is my code so far.  It does not produce anything.
<?php
$result_max = mysqli_query("SELECT max_records FROM company_information"); 

$result_cnt = mysqli_query("SELECT user_id FROM users"); 

    /* determine number of rows result set */
    $row_cnt = mysqli_num_rows($result_cnt);
	

if ($row_cnt > $result_max) {
    printf("You have exceeded the maximum number of users for this account. Please request more.");
    exit();
} 

if ($row_cnt < $result_max) {
    echo "The html form will go here";
 }    

?>

Open in new window

chaddcarrAsked:
Who is Participating?
 
chaddcarrAuthor Commented:
//retrieve current user count
$count_user_sql = "SELECT COUNT(*) as user_count FROM users";
$count_user_result = mysql_query($count_user_sql);
$count_user_row = mysql_fetch_array($count_user_result);

$current_user_count = $count_user_row["user_count"];

//retrieve max_users
$sql = "SELECT max_records FROM company_information WHERE company_id=1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$max_users = $row['max_records'];
0
 
GaryCommented:
You need to get the count of $result_max like you do with $result_cnt
0
 
Ray PaseurCommented:
This article teaches how to use PHP and MySQLi.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

Some of the things you need to add include error checking.  The MySQLi_Query() function has a return value.  If your script does not test this value, you cannot know whether the function succeeded or failed!  Fortunately all of the PHP functions are documented in the online man pages, so when you don't know what a function is expected to return, or when you're getting unexpected results, you can look them up online.  No need to guess ever again!

I'm not sure how your data tables are organized or loaded, but if you want to show us the test data you're using we can probably show you a complete and working code example.  Or you can just refer to the article to see error checking and counting the rows in the results set.  You might also want to learn about SELECT COUNT(*) which can be used with a WHERE clause.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
chaddcarrAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for chaddcarr's comment #a40293941

for the following reason:

Comments provided by other users provided no assistance.
0
 
GaryCommented:
Very first comment tells you you need to get the recordset count and not compare the a number against a recordset.
0
 
Ray PaseurCommented:
Agree with Gary's  Expert Comment.  The code snippet in the question evinces a complete lack of understanding about how to use PHP and MySQL together.  There's nothing wrong with ignorance -- most of us started somewhere else a long time ago.  But there is a learning process that we had to go through to build up enough of a knowledge base to know whether the comments provided any assistance or not.  

If you want to get started learning PHP and MySQL, this article can help you get that knowledge base.  
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Don't demand too much of yourself all at once -- most of us have been doing this for years!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.