fairly new to PDO. Anyway i have a table called Usage which should contain the usage amount, the date it was added and the users account number which is stored in a variable called $loggedInUser
I have the following code:
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->dbconn = $db;
$this->loggedInUser = $_SESSION['user_session'];
}
public function enterGasReadings($gUsage)
{
try
{
$gstmt = $this->dbconn->prepare("
INSERT INTO gas_readings
(GasUsage, DateAdded, AccountNumber)
VALUES
(:gUsage, NOW(), :accNum)");
$gstmt->bindparam(":gUsage", $gUsage);
$gstmt->bindparam(":accNum", $loggedInUser);
$gstmt->execute();
return $gstmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
and this is my post section:
if(isset($_POST['btn-submitGasUsage']))
{
$gUsage = strip_tags($_POST['txtGasUsage']);
if($gUsage=="") {
$gasError[] = "Please Enter a Number";
}
try {
if($newReading->enterGasReadings($gUsage)){
$gasNotif[] = "Reading successfully entered.";
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
However, i keep getting the SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'AccountNumber' cannot be null
error
Ive added the backticks ` in but that didnt seem to make a difference.
Any ideas? Thanks!