1

the following returns false and i don't know how to find out what exactly is wrong.

$stmt = $dbo->stmt_init();
if($stmt->prepare("INSERT INTO transactions ('id', 'time') VALUES ('',?)")) // returns false
{
}

i have another statement which does an select open at that time. is it a problem to have more than one statements?

clamp
  • 33,000
  • 75
  • 203
  • 299

3 Answers3

5

Have you verified that you are connecting to the database successfully?

/* check connection */
if ( mysqli_connect_errno() ) {
    printf("Connect failed: %s\n", mysqli_connect_error());
}

As far as figuring out what's wrong with your prepared statement, you should be able to display $stmt->error, which will return a string description of the latest statement error, and $dbo->error, which will return the latest mysqli error.

printf("Error: %s.\n", $stmt->error);
Ari Patrick
  • 446
  • 2
  • 5
  • thanks it gives me: DB Error: prepare Commands out of sync; you can't run this command now – clamp Oct 17 '11 at 16:24
  • 2
    The following SO questions may be of use to you: http://stackoverflow.com/questions/3632075/mysqli-giving-commands-out-of-sync-error-why http://stackoverflow.com/questions/614671/commands-out-of-sync-you-cant-run-this-command-now1 – Ari Patrick Oct 17 '11 at 16:36
0

You don't want single quotes around your table names. It should look like this:

$stmt = $dbo->stmt_init();
if($stmt->prepare("INSERT INTO transactions (id, time) VALUES ('', ?)")) {

}
Aaron
  • 10,386
  • 13
  • 37
  • 53
0

just check whether those columns are properly entered... as i was getting same error coz i mentioned non existing column name in the query..

shridhar
  • 35
  • 1
  • 4