0

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

解析错误:语法错误,第 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

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

4

2 回答 2

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
于 2013-09-27T16:28:20.850 回答
1

int isn't a keyword in PHP. So it's interpreting that as a variable name. Which is then immediately following by another variable name ($num_rows), which is what the parser doesn't expect.

I think you mean this:

$num_rows = 0;

You don't need to declare a variable type. The interpreter will discern the type when it needs to.

于 2013-09-27T16:20:06.327 回答