0

I am trying to insert a boolean value into MySql using php. I have the following code:

$query = "insert into credentials values (?, ?, ?, ?, ?, ?, ?)";
$stmt = $db->prepare($query);
$stmt->bind_param("dssssid", $userID, $websiteName, $username, $password, $dateCreated, $currentLogin, 
$categoryID);
$stmt->execute();
echo $stmt->affected_rows." Credentials inserted into database";

The value dateCreated is a 1 for true but when I try to use my webpage to enter it i get the following error:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\usernamesandpasswords\insertcredentials.php:50 Stack trace: #0 {main} thrown in C:\xampp\htdocs\usernamesandpasswords\insertcredentials.php on line 50

I have tried using it as a string, int and casted (int) to it but I still get the error.

Dharman
  • 26,923
  • 21
  • 73
  • 125
  • I think it's actually complaining about `$stmt` being a boolean and not the value you are trying to bind. This can be because the prepare fails (and returns false). As a general point - I would recommend always including the column names you are inserting into - helps in case the columns are re-ordered for some reason. – Nigel Ren Dec 10 '19 at 07:22
  • Could it be because the table has 8 attributes and I am only inserting 7? The value I am not inserting is just a value that keeps count of the number of credentials added. @NigelRen – cprogramnewb Dec 10 '19 at 07:33
  • If you have error reporting enabled, it should tell you what the error is - better than guessing. Some fields may have defaults, some can be null - this is why I suggested listing the columns in your insert as it then is clear where you intend the values to be inserted. – Nigel Ren Dec 10 '19 at 07:35

0 Answers0