php脚本给出意外的文件结尾错误


php script giving error unexpected end of file

任何主体都能说出这个脚本给出的原因吗

    <?php 
      session_start();
      $con = mysqli_connect("localhost", "root", "", "QSTNS");
          if (mysqli_connect_errno()) {
              echo "Failed to connect to MySQL: ".mysqli_connect_error();
              $res = mysqli_query($con, 'SELECT COUNT(*) FROM qstns');
              $row = mysqli_fetch_array($res);
              $scoreis = 0;

              for ($i = 0; $i < $row[0]; $i++) {
                  $scoreis = $scoreis + $_SESSION['scr'][$i];
              }
              echo $scoreis;
              mysqli_close($con);                               
?>

错误为:分析错误:语法错误,在第32行的C:''wamp''www''quiiz_portal''scoreis.php中出现意外的文件结尾

您在if (mysqli_connect_errno()) {之后忘记关闭},请尝试以下操作:

$con = mysqli_connect("localhost", "root", "", "QSTNS");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
$res = mysqli_query($con, 'SELECT COUNT(*) FROM qstns');
$row = mysqli_fetch_array($res);
$scoreis = 0;
for ($i = 0; $i < $row[0]; $i++) {
    $scoreis = $scoreis + $_SESSION['scr'][$i];
}
echo $scoreis;
mysqli_close($con);
if (mysqli_connect_errno()) {

没有匹配的大括号,您需要说明if在哪里结束