如何使我的PHP文件停止显示“意外的$ EOF”错误?

时间:2018-10-08 11:56:12

标签: php

感谢我让我在Stackoverflow上过得很愉快。 我决定将000webhost用作数据库。我是PHP初学者。 我在URL后面输入/Register.php,这是我的PHP文件的文件,以便在用户注册时将其上传到数据库。 过去曾说过“连接成功”,但我已经修复了错误行。我现在无法解决的一个问题如下:

这是我的php文件:

<?php
$servername = 'localhost';
$username = 'xxx';
$password = 'xxx';
$database = 'xxx';

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";

$query ="INSERT INTO user VALUES (?, ?, ?, ?, ?)";
$statement = mysqli_prepare($conn, $query);

mysqli_stmt_bind_param($statement, "issis" ,$id, $name, $username, $age, $password);
if(isset($_POST['name'])){ 
    $name = $_POST['name']; 
}
if(isset($_POST['username'])){ 
    $username = $_POST['username'];
    $username = $_POST["username"];
    $age = $_POST["age"];
    $password = $_POST["password"];

    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    print(json_encode($response));
    printf("%d Row embed.\n", mysqli_stmt_affected_rows($statement));
    mysqli_stmt_close($statement);
?>

如何

在Google Chrome浏览器中看到此错误行

Parse error: syntax error, unexpected end of file in /storage/ssd1/298/7395298/public_html/Register.php on line 38

当我在000webhost中查看它时

Syntax Error, Unexpected $EOF

我希望在正确的印象下,一旦问题已纠正,信息将成功发送到我的数据库。

任何纠正此错误的帮助都将引起感激。非常感谢!

2 个答案:

答案 0 :(得分:0)

如果没有关闭,您的最后一个

if(isset($_POST['name'])){ $name = $_POST['name']; }
    if(isset($_POST['username'])){ $username = $_POST['username'];
    $username = $_POST["username"];
    $age = $_POST["age"];
    $password = $_POST["password"];

    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    print(json_encode($response));
    printf("%d Row embed.\n", mysqli_stmt_affected_rows($statement));
    mysqli_stmt_close($statement);

}

答案 1 :(得分:0)

尝试

error_reporting(0);

这将在页面上隐藏所有错误...

但是有一个错误,您也没有关闭带有括号的最后一个if标签

<?php

    $servername = 'localhost';
    $username = 'xxx';
    $password = 'xxx';
    $database = 'xxx';

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";

    $query ="INSERT INTO user VALUES (?, ?, ?, ?, ?)";
    $statement = mysqli_prepare($conn, $query);


    mysqli_stmt_bind_param($statement, "issis" ,$id, $name, $username, $age, $password);


    if(isset($_POST['name'])){ $name = $_POST['name']; }

    if(isset($_POST['username'])){ $username = $_POST['username'];
    $username = $_POST["username"];
    $age = $_POST["age"];
    $password = $_POST["password"];

    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    print(json_encode($response));
    printf("%d Row embed.\n", mysqli_stmt_affected_rows($statement));
    mysqli_stmt_close($statement);

    }
?>