I have a community where virtual pilots can log hours flight by flight. I have a downloads page that I want pilots to access but only after logging 10 hours. This code is an attempt to get the users logged hours and then show them the downloads page link if they meet the 10 hour requirement. It fetches the correct hours but gives the same result whether a pilot has 10 hours or 1. It may be that the database is holding varchar instead of int perhaps. Weeks and weeks, I’ve played with this, any ideas? Switch may be better, I’ve tried both. New to coding. Thanks!
[php]<?php
// Connect to the DB
require_once(‘connectvars.php’);
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
// Get the users total flight hours
mysql_select_db(“flight_db”, $con);
$query = “SELECT SUM(vfrhrs + ifrhrs) AS total FROM logbook WHERE user_id = '” . $_SESSION[‘user_id’] . “’ AND approved=1 GROUP BY user_id”;
$result = mysql_query($query) or die(mysql_error());
// Print out result to make sure it has pulled the session users total hours from database
while($row = mysql_fetch_array($result)){
echo "Current Hours: ". $row[‘total’];
echo “
”;
}
$row[‘total’] = $currenthours;
// Again, print this to make sure this worked
echo("$currenthours");
// Test to see if user has enough hours to proceed to download page link
if ($currenthours > 10) {
echo “Show The Downloads Page Link or redirect to downloads page”;
}
else ($currenthours < 10) {
echo “You have not logged enough hours, you need at least 10 to access our super duper downloads page”;
}
?>
[/php]