我有以下代码:
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();
}
}
这是我的帖子部分:
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();
}
}
但是,我一直收到SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'AccountNumber' cannot be null
错误
我添加了反引号,但这似乎没什么区别。
有什么想法吗? 谢谢!