$ conn-> prepare keeps returning false

$ conn is the database connection I used earlier to get information to make it work. preparation returns false and I don't know why.

$updateWeight = "insert into $username (weight, date) values (?,?)";
if($stmt = $conn->prepare($updateWeight))
{
    $stmt->bind_param("is",$weight,$date);
    $stmt->execute();
    die("Added ". $weight . " " . $date);
}
else
{
    die( "$updateWeight with $weight and $date error 1");
}

      

This returns the value "insert into test (weight, date) (?,?) With error 150 and 2015/06/16 1".

Here is the table, as far as I can tell, all is well.

mysql> select * from testing;
+----+--------+------------+
| id | weight | date       |
+----+--------+------------+
|  1 |    200 | 2015/06/10 |
+----+--------+------------+
1 row in set (0.01 sec)

      

I'm sure the error is something insignificant and stupid, but I can't seem to find it.

I copied and pasted the command into mysql and it worked after changing the variables

mysql> insert into testing (weight, date) values (150,"2015/06/15"); 
Query OK, 1 row affected (0.02 sec)

      

+3


source to share


2 answers


I fixed it by putting $ conn-> close (); and then recreate $ conn as I used it earlier



0


source


Note:

Your request uses the reserved word - DATE

. What you can do to get around this is to use the downside (`).

$updateWeight = "INSERT INTO `$username` (`weight`, `date`) VALUES (?,?)";

      



If that doesn't solve your problem, let's report the errors to determine the error why it is returning false .

Put this in your condition else()

:

printf("Errormessage: %s\n", $conn->error);

      

0


source







All Articles