Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.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_Html - Fatal编程技术网

Php 提交表单时,我收到错误,但不确定原因

Php 提交表单时,我收到错误,但不确定原因,php,html,Php,Html,为什么我在提交此表单时收到回音声明“错误” 我从for register.php获得了这段代码 到昨天为止,它对我的用户运行良好,但似乎找不到原因 我想可能是我的config.php,但如果用户名已经在使用中,它会打印错误消息,因此看起来不是config.php。我给网站发了一条消息,说我是从那里得到代码的,他们帮不了我 <?php // Include config file require_once "config.php"; // Define variables and init

为什么我在提交此表单时收到回音声明“错误”

我从for register.php获得了这段代码

到昨天为止,它对我的用户运行良好,但似乎找不到原因

我想可能是我的config.php,但如果用户名已经在使用中,它会打印错误消息,因此看起来不是config.php。我给网站发了一条消息,说我是从那里得到代码的,他们帮不了我

<?php
// Include config file
require_once "config.php";

// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){

    // Validate username
    if(empty(trim($_POST["username"]))){
        $username_err = "Please enter a username.";
    } else{
        // Prepare a select statement
        $sql = "SELECT id FROM sign_in_account WHERE username = ?";

        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "s", $param_username);

            // Set parameters
            $param_username = trim($_POST["username"]);

            // Attempt to execute the prepared statement
            if(mysqli_stmt_execute($stmt)){
                /* store result */
                mysqli_stmt_store_result($stmt);

                if(mysqli_stmt_num_rows($stmt) == 1){
                    $username_err = "This username is already taken.";
                } else{
                    $username = trim($_POST["username"]);
                }
            } else{
                echo "Oops! Something went wrong. Please try again later.";
            }
        }

        // Close statement
        mysqli_stmt_close($stmt);
    }

    // Validate password
    if(empty(trim($_POST["password"]))){
        $password_err = "Please enter a password.";     
    } elseif(strlen(trim($_POST["password"])) < 6){
        $password_err = "Password must have atleast 6 characters.";
    } else{
        $password = trim($_POST["password"]);
    }

    // Validate confirm password
    if(empty(trim($_POST["confirm_password"]))){
        $confirm_password_err = "Please confirm password.";     
    } else{
        $confirm_password = trim($_POST["confirm_password"]);
        if(empty($password_err) && ($password != $confirm_password)){
            $confirm_password_err = "Password did not match.";
        }
    }

    // Check input errors before inserting in database
    if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){

        // Prepare an insert statement
        $sql = "INSERT INTO sign_in_account (username, password) VALUES (?, ?)";

        if($stmt = mysqli_prepare($link, $sql)){
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);

            // Set parameters
            $param_username = $username;
            $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash

            // Attempt to execute the prepared statement
            if(mysqli_stmt_execute($stmt)){
                // Redirect to login page
                header("location: login.php");
            } else{
                echo "Something went wrong. Please try again later. error: 1";//Error 1 = form submission
            }
        }

        // Close statement
        mysqli_stmt_close($stmt);
    }

    // Close connection
    mysqli_close($link);
}
?>


在成功提交结果时,输出应该转到my login.php页面,但打印我的echo语句“echo”时出错。请稍后再试。错误:1“;”

有关数据库连接的某些内容已断开
mysqli\u stmt\u execute($stmt)
返回
false
。你对此做了任何更改吗?哪个“错误”声明?而不是说“错误:1”为什么不实际检查错误消息?@theblackips我已经两周没有更改服务器上的任何内容了。但它在两天前就开始工作了,因为我们在我的数据库中创建了新用户。然后我被告知它昨天不工作。@CodyO'Meara正如其他人所说的,请检查您的php错误日志。有关您的数据库连接的某些内容已断开
mysqli\u stmt\u execute($stmt)
返回
false
。你对此做了任何更改吗?哪个“错误”声明?而不是说“错误:1”为什么不实际检查错误消息?@theblackips我已经两周没有更改服务器上的任何内容了。但它在两天前就开始工作了,因为我们在我的数据库中创建了新用户。然后我被告知它昨天不工作。@CodyO'Meara正如其他人所说,请检查您的php错误日志。