user3335368
user3335368

Reputation: 11

Object of class mysqli_stmt could not be converted to string

.I have a Problem when I insert Time To the database there's an error..

<?php

include ('includes/config.php');

$mysqli = new mysqli(DB_SERVER, DB_UNAME, DB_PASSWD, DB_NAME);

if (!$mysqli) {
    throw new Exception($mysqli->connect_error, $mysqli->connect_errno);
}


$tqry = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");

if (!$tqry) {
    throw new Exception($mysqli->error);
}

$tqry->bind_param('s', $tqry);
$tqry->execute();
?>

What Is the error with this?

thanks in advance..

Upvotes: 0

Views: 2332

Answers (1)

Brandon - Free Palestine
Brandon - Free Palestine

Reputation: 16656

It's here:

$tqry->bind_param('s',$tqry);

You are binding parameter s to $tqry which is your MySQL prepared statement. You must store the time in a different variable. See:

$tqry = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");

You set $tqry to time, then you overwrite it with a prepared statement instead. You should use a different variable name:

$now  = time();
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");

Then do:

$tqry->bind_param('s', $now);

Upvotes: 1

Related Questions