PHP Parsing/Syntax Error Unexpected End of File

This question already has an answer here:

  • PHP syntax error “unexpected $end” 7 answers

  • You have not clased the mysql_connect errorno() brackets. Use the code below

    <?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);
    ?>
    

    Hope this helps you


    你还没有关闭你的代码

    <?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/69810.html

    上一篇: PHP API数组循环

    下一篇: PHP分析/语法错误意外的文件结束