I am trying to create an insert statement using data posted from the previous page and binding them to the statement
My SQL insert statement is this:
// insert new user
$db = createConnection();
$insertquery="insert into comments (com, userid, comdate, blogpost) values (?,?,?,?)";
$inst=$db->prepare($insertquery);
$inst->bind_param("sisi", $comment, $user, $today, $id);
$inst->execute();
$inst->close();
When I turn on debugging for PHP this is the error I receive
Fatal error: Call to a member function bind_param() on boolean in /blog/xcomment.php on line 29
The data that is being passed in for the bind_param is
Array ( [comment] => My New Comment [blogid] => 1 ) 2016-01-07 12:31:50
$user = $currentuser['userlevel'];
$comment = $_POST['comment'];
$id = $_POST['blogid'];
$today = date("Y-m-d H:i:s");
尝试改用单引号:
$inst->bind_param('sisi', $comment, $user, $today, $id);
http://php.net/manual/en/mysqli-stmt.prepare.php
$db->prepare - return boolean.
it's correct usage:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$city = "Amersfoort";
/* create a prepared statement */
$stmt = $mysqli->stmt_init();
if ($stmt->prepare("SELECT District FROM City WHERE Name=?")) {
/* bind parameters for markers */
$stmt->bind_param("s", $city);
/* execute query */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($district);
/* fetch value */
$stmt->fetch();
printf("%s is in district %s\n", $city, $district);
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.