解析错误:语法错误,<file> </file>中的意外T_VARIABLE

时间:2013-09-27 16:16:42

标签: php mysql

请有人告诉我哪里错了?运行脚本时出现以下错误:

  

解析错误:语法错误,第32行的C:\ wamp \ www \ baljeet2 \ ViewAllPolicy1.php中的意外T_VARIABLE

这是我的完整代码:

<!DOCTYPE html>
<html>
<body bgcolor='white'>
<?PHP
include 'config.php';
session_start();

//if ($_SESSION['auth']!='TRUE') {

//header ("Location: ../a_login.php");

//}

?>

<?PHP

$con=mysqli_connect($host,$user,$pass,$DB_name);

 if (mysqli_connect_errno($con))
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   else
   {
   echo "";
   }  

$result = mysqli_query($con,"SELECT * FROM policydetail1");
echo "pass<br>";

int $num_rows=0;


$num_rows= mysql_num_rows($result);
if ($num==0) {
  // Show message
    echo "No record Found";
} else {
  // do your while stuff here

while($row = mysqli_fetch_array($result))
{
echo $row['CompanyName']." ".$row['PolicyNo']." ".$row['OD']." ".$row['ThirdParty']." ".$row['ServiceTaxRate']." ".$row['TotalAmount']." ".$row['Discount']." ".$row['CommissionRate']." ".$row['Commission']." ".$row['CommissionStatus']." ".$row['Date']."<br>";
}

}

    mysqli_close($con);





     //echo "<div align='center'><div style='background-color:#4682B4; color:white; width:1000px; height:30px; text-align:center; font-family:trebuchet ms;'>Policy Add Succefully!!!</div></div><br> <div align='center'><a href='Add Policy Form.html'>Add more records</a><a href='Add Policy Form.html'> <BR>Back to Main Menu</a></div>";

    ?>

我是PHP新手并且很难找到这个错误。第32行的代码如下:

int $num_rows=0; //Here I am getting error

我还检查了分号和语法,但没有找到。

2 个答案:

答案 0 :(得分:3)

Php是动态类型语言。这意味着变量没有类型。运行时是否以变量内容为基础知道类型。

<?php

    $var = 0;     echo gettype($var);  // integer
    $str = 'str'; echo gettype($str);  // string
    $boo = false; echo gettype($boo$); // boolean

如果需要,可以施放值:

<?php

    $integer = '3';              // now is a string
    $number = 2 * (int)$integer; // '3' becomes an integer with (int)
    echo $number;                // will print 6

答案 1 :(得分:1)

int不是PHP中的关键字。所以它将其解释为变量名称。然后紧接着另一个变量名称($num_rows),这是解析器不期望的。

我认为你的意思是:

$num_rows = 0;

您无需声明变量类型。解释器将在需要时识别类型。