急请高手指导关于Mysqli的prepare出错有关问题

WBOY
Release: 2016-06-13 12:24:35
Original
795 people have browsed it

急!!!请高手指导关于Mysqli的prepare出错问题
很久没写程序了,由于php5.0升级的mysqli类操作数据库有很多优点,本人想尝试用mysqli的方法操作数据库,经过从网上查资料、看手册,浏览、删除都能正常实现,唯独插入功能总是提示错误:Fatal error: Call to a member function prepare() on null in D:\xampps\htdocs\txl\addbook.php on line 20  。
快愁死我了,难道这个问题解决不了我要放弃Mysqli吗?请高手指点我的代码错在哪里?还是服务器的问题?(服务器我用的是Xampps1.9.7集成环境)

if($_POST['contacts'] == "true")
{
    $stmt = $mysqli->prepare("INSERT INTO contactsuser(bookUname, bookDep, bookDuty,bookphone,bookTel,bookEmail,bookGid) VALUES (?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param('sssd', $bookUname, $bookDep, $bookDuty, $bookphone, $bookTel, $bookEmail, $bookGid);

    $bookUname = $_POST['bookUname'];
    $bookDep = $_POST['bookDep'];
    $bookDuty = $_POST['bookDuty'];
    $bookphone = $_POST['bookphone'];
    $bookTel = $_POST['bookTel'];
    $bookEmail = $_POST['bookEmail'];
    $bookGid = $_POST['bookGid'];

    /* execute prepared statement */
    $stmt->execute();
    printf("%d Row inserted.\n", $stmt->affected_rows);
    /* close statement and connection */
    $stmt->close();
    exit;
}
------解决思路----------------------
$mysqli 不是 mysqli 对象
------解决思路----------------------
试试面向过程风格的方法:

$stmt = mysqli_prepare($link, "INSERT INTO contactsuser(bookUname, bookDep, bookDuty,bookphone,bookTel,bookEmail,bookGid) VALUES (?, ?, ?, ?, ?, ?, ?)")
Copy after login



------解决思路----------------------
mysqli_stmt_bind_param($stmt,'ssssssd', $bookUname, $bookDep, $bookDuty, $bookphone, $bookTel, $bookEmail, $bookGid);
Copy after login

http://php.net/manual/zh/mysqli-stmt.bind-param.php

The number of variables and length of string types must match the parameters in the statement.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!