Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我在数据库的insert中抛出和错误使用mysqli准备的语句_Php_Mysql_Mysqli_Prepared Statement - Fatal编程技术网

Php 我在数据库的insert中抛出和错误使用mysqli准备的语句

Php 我在数据库的insert中抛出和错误使用mysqli准备的语句,php,mysql,mysqli,prepared-statement,Php,Mysql,Mysqli,Prepared Statement,根据之前的一篇文章,我试图学习准备好的语句,以便正确地清理一切 这是我的表格: <form name="login" action="regi.php" method="post" accept-charset="utf-8"> <label for="username">Username: </label><br /> <input type="username" name="username" pl

根据之前的一篇文章,我试图学习准备好的语句,以便正确地清理一切

这是我的表格:

<form name="login" action="regi.php" method="post" accept-charset="utf-8">
        <label for="username">Username: </label><br />
            <input type="username" name="username" placeholder="Handle" required><br />
            <input type="hidden" name="sign_up_date" value="<?php echo $_POST['sign_up_date'] ?>">
        <label for="usermail">Email: </label><br />
            <input type="email" name="usermail" placeholder="yourname@email.com" required><br />
        <label for="password">Password: </label><br />
            <input type="password" name="password" placeholder="password" required><br />
            <input type="submit" value="Login">
    </form>
这是我的insert.php页面:

include("mysql_connect.php");
include("classes/insert.php");


if (!mysqli_query($mysqli,$stmt))
  {
  die('Error: ' . mysqli_error($mysqli));
  }
echo "1 record added";

mysqli_close($mysqli);
$user = $_POST['username'];
$email = $_POST['usermail'];

$stmt = $mysqli->stmt_init();
if (!$stmt) {
    echo "Init failed";
} else {
    $cmd = "INSERT INTO people (username, email, sign_up_date) VALUES (?, ?, NOW() )";
    if ($stmt->prepare($cmd)) {
        $stmt->bind_param('ssd', $user, $email );
        $stmt->execute();

        echo $stmt->affected_rows . "row(s) inserted";

        $stmt->close();

    } else {
        echo "Prepare failed";
    }   
}
以下是我的错误消息:

通过UNIX套接字0行插入器的本地主机错误:

我想我在insert.php页面上做错了什么


任何帮助都将不胜感激。谢谢。

您可以将查询编写为存储过程。。。这样,实际查询存储在db中,而不是php文件中

此外,根据您目前的情况,您似乎没有将正确的值插入到表中的正确列中

下面是存储过程方法

//更新php文件,以便读取以下变量

$cmd = call `people`.`procedurename` (?,?)";
$stmt->bind_param($user, $email ); 
登录mysql并使用此代码创建一个存储过程

DELIMITER $$
CREATE PROCEDURE `people`.`procedurename` (
IN username VARCHAR(50),
IN email VARCHAR(50)
)
BEGIN
INSERT INTO people (username, email, sign_up_date) VALUES (username, email, NOW());
END
$$

祝你好运:

'ssd',但只有两个字符串变量?我应该只使用'ss'吗?嗯,ss似乎工作得很好。。。其他一切看起来都正常吗?在INSERT语句中有两个参数问号,您正在尝试biind 3个变量