Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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 绑定新参数,什么';这个密码怎么了?_Php_Mysql_Mysqli - Fatal编程技术网

Php 绑定新参数,什么';这个密码怎么了?

Php 绑定新参数,什么';这个密码怎么了?,php,mysql,mysqli,Php,Mysql,Mysqli,我可以确认已成功检索到两个变量$location和$placename。运行此代码的结果是成员表已成功更新,但放置表未更新,脚本将我转储到一个空白HTML中。我发现绑定参数不喜欢接受硬编码值。在我尝试获取最后一个插入的ID之前,我试图通过在列中插入一个值1来“测试”我的代码。Fred建议的错误报告真的很有帮助(正如您所看到的,我已经实现的其他建议一样) 修改后的代码: // Insert the new user into the database // This

我可以确认已成功检索到两个变量
$location
$placename
。运行此代码的结果是
成员
表已成功更新,但
放置
表未更新,脚本将我转储到一个空白HTML中。

我发现
绑定参数
不喜欢接受硬编码值。在我尝试获取最后一个插入的ID之前,我试图通过在列中插入一个值1来“测试”我的代码。Fred建议的错误报告真的很有帮助(正如您所看到的,我已经实现的其他建议一样)

修改后的代码:

        // Insert the new user into the database
        // This WORKS, and was copied from an example
        if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)")) {
            $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
            // Execute the prepared query.
            if (! $insert_stmt->execute()) {
                header('Location: ../error.php?err=Registration failure: MEMBER. Please contact the developer.');
            }
            $insert_stmt->close();



            // If user inserted, add place with user as owner
            // This DOESN'T work, and was added by me
            //$ownerid = $mysqli->lastInsertId();
            $placename = $_POST['placename'];
            $placename = mysqli_real_escape_string($mysqli, $placename);
            $location = $_POST['autocomplete'];
            $location = mysqli_real_escape_string($mysqli, $location);
            if ($place_stmt = $mysqli->prepare("INSERT INTO places (member_owner, location, name) VALUES (?, ?, ?)")) {
                $place_stmt->bind_param('iss', 1, $location, $placename);
                if (! $place_stmt->execute()) {
                    header('Location: ../error.php?err=Registration failure: PLACE. Please contact the developer.');
                }
            }
            $place_stmt->close();
        }

        header('Location: ./register_success.php');

谢谢你的帮助

告诉你,你有一个微妙的错误。这两个头调用都将被调用(error.php redirect和register_success.php redirect),因为在错误重定向之后您没有退出/死亡。另外,一个空白HTML页面通常表示一个致命的php错误,请在打开php标记后立即检查日志并将错误报告到文件顶部,例如
我将使用
else{header('Location:./register_success.php');exit;}
在两个
if
条件上,并从现在的位置删除
header('Location:./register_success.php');
。还要检查列类型。如果要绑定参数,则不应使用
mysqli_real_escape_string
。。。
    // Insert the new user into the database 
    if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)")) {
        $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
        // Execute the prepared query.
        if (! $insert_stmt->execute()) {
            header('Location: ./error.php?err=Registration failure: MEMBER. Please contact the developer.');
            exit;
        }
        $insert_stmt->close();

        // If user inserted, add place with user as owner
        $ownerid = $mysqli->insert_id;
        if ($place_stmt = $mysqli->prepare("INSERT INTO places (member_owner, location, name) VALUES (?, ?, ?)")) {
            $place_stmt->bind_param('iss', $ownerid, $location, $placename);
            if (! $place_stmt->execute()) {
                header('Location: ./error.php?err=Registration failure: PLACE. Please contact the developer.');
                exit;
            }
        }
        $place_stmt->close();
        header('Location: ./register_success.php');
    }