Null value in a table gives Error message

I want to offer users a trial period in a website.
When the users table is created there is no value in trial cell. it has NULL inside.

When a user wants to use a trial period, I check if the user already used this one time offer.

Here is the code:


require_once 'includes/fetch.php';

$username = $_SESSION['username'];

$test = check_free_trial_availability($username);



Here is the function

function check_free_trial_availability($username)
	global $db;
		$sql = "SELECT trial
				FROM users 
				WHERE username = :username";
		$stmt = $db->prepare($sql);
        $stmt->bindParam(':username', $username, PDO::PARAM_STR);
		if($stmt->rowCount() == 0)
		return 0;
		return $stmt->fetchAll(PDO::FETCH_ASSOC);
	catch(Exception $e) 
	   return false;        

here is the eror message

How do I solve the problem.
There is no value since the user has’nt subscribed for a trial period

That error means that $db is null. Either that’s the wrong variable name for the database connection or it’s the right name but it contains a null.

This error suggests that $db is NULL.
Check your database connection is working.

Sessions have a limited lifetime, try using local storage or cookies:

Also as@SamA74 suggested, try closing and reconnecting the $username with $password and test the results before calling prepare(…)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.