I have a query that outputs the resulting data into a table. I have two fields in that table that are vital for this if statement: Max Capacity and Current Capacity. These are from our database, from the same table.
I want to write an if statement:
if (Max_C == Current_C){
echo "Sorry, course is full.";
}
else{
$insert = mysql_query ("insert into blahblahblah... ");
}
How do I do this? How do I specify the max_c and current_c from the db?
That section of code:
if($courseandtime) { $max_e = $courseandtime['MaxEnrollment']; $current_e = $courseandtime['COUNT(REGISTERED.SID)']; }
if ($current_e < $max_e) {
echo "
<form action='register-exec.php' method='post'>
<label>Time: $_POST[Time]</label><br>
<input type='hidden' value='$Time' /><br><br>
<label>Student ID:</label><br>
<input type='text' name='SUCID' id='SUCID' /><br><br>
<label>CID: $_POST[CID]</label><br>
<input type='hidden' name='CID' id='CID' /><br><br>
<label>SID: $row['SID']</label><br>
<input type='hidden' name='SID' id='SID' /><br><br>
<button type='submit'>Register</button>
</form>
";
}
else {
echo 'Sorry, were full!';
}
mysql_*functions. They are no longer maintained and community has begun the deprecation process . Instead you should learn about prepared statements and use either PDO or MySQLi. If you care to learn, here is a quite good PDO-related tutorial.