PHP分析/语法错误意外的文件结束

这个问题在这里已经有了答案:

  • PHP语法错误“意外$结束”7个答案

  • 你还没有将mysql_connect errorno()括起来。 使用下面的代码

    <?php
    
    // Create connection
    $con=mysqli_connect("host","username","password","db");
    
    // Check connection
    if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    // escape variables for security
     $name = mysqli_real_escape_string($con, $_POST['name']);
    
     $sql="INSERT INTO testing (Name)
     VALUES ('$name')";
    
     if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    
     echo "1 record added";
    
     mysqli_close($con);
    ?>
    

    希望这可以帮助你


    你还没有关闭你的代码

    <?php
    
    // Create connection
    $con=mysqli_connect("host","username","password","db");
    
    // Check connection
    if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    die; // append this
     } //apend this 
    // escape variables for security
     $name = mysqli_real_escape_string($con, $_POST['name']);
    
     $sql="INSERT INTO testing (Name)
     VALUES ('$name')";
    
     if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    
     echo "1 record added";
    
     mysqli_close($con);
    
    
    ?>
    

    你的if (mysqli_connect_errno()) {没有关闭

    <?php
    
    // Create connection
    $con=mysqli_connect("host","username","password","db");
    
    // Check connection
    if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    // escape variables for security
     $name = mysqli_real_escape_string($con, $_POST['name']);
    
     $sql="INSERT INTO testing (Name)
     VALUES ('$name')";
    
     if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }
    
     echo "1 record added";
    
     mysqli_close($con);
    ?>
    
    链接地址: http://www.djcxy.com/p/69809.html

    上一篇: PHP Parsing/Syntax Error Unexpected End of File

    下一篇: Parse error: syntax error, unexpected end of file in