Compare PHP Variable To Database

brduncan

New Member
I have a form that when submitted, the data is set into a database. When the form is submitted I want to set a specific variable to either active or inactive.

What I'm looking to do is set the max number of active memebers to 10. I want my process.php file to automatically search through the database and if there are 10 active states, set the varaible to inactive.

Anyone have any ideas?
 

brduncan

New Member
Actaully, I just figured it out. But i was wondering if anyone new if there was a way to search for either one variable or another when using MySQL WHERE?
 

brduncan

New Member
found a work around. Here is the code if anyone is interested

$sqlActiveInactive = mysql_query("SELECT ActiveInactive FROM zxc WHERE ActiveInactive='active'"); //selecting active column for active
$sqlActivePending = mysql_query("SELECT ActiveInactive FROM zxc WHERE ActiveInactive='pending'"); //selecting active column for pending
$numberOFactive = mysql_num_rows($sqlActiveInactive); //getting number of rows with active
$numberOFpending = mysql_num_rows($sqlActivePending); //getting number of rows with pending
$numberOFactivepending = $numberOFactive + $numberOFpending; //set equal to active+pending

if(($numberOFactivepending) <= 9)
{
$ActiveInactive = 'active';
}//set to active if less than 10 active && pending
else
{
$ActiveInactive = 'inactive';
}//else set inactive
 

v2Media

Member
There's a few ways of doing this. Transferring the counting to mysql, such a query would read:-

SELECT `ActiveInactive` , COUNT( * ) AS `Total`
FROM zxc
WHERE `ActiveInactive` = 'active'
GROUP BY `ActiveInactive`

You would then mysql_fetch_assoc() to get the number of actives from `Total`.
 

Razorback64

New Member
Are you starting every page that uses sessions with

session_start();

?

I would make the 'Delete' button dependent on if the user's id equals the id on the logged in user, and make a second check on the script to make sure the logged in user doesn't match any user being deleted.

The values in sessions remain so long as there is activity within the timeframe of the session timeout (default is 20 minutes) or until you specifically tell the session to unset.

EDIT:
Only the pages that utilize sessions need to start with the session_start (which has to be the first line after the <?php). If you are trying to create a controlled environment, I recommend every page that a user needs to get to have that in the beginning. You also should check the user session to make sure someone who isn't logged in can't get into the forms.
 
Last edited:
Top