2013-09-27 83 views
0
意外T_VARIABLE

請有人告訴我,我錯了嗎?我收到的時候我運行腳本以下錯誤:解析錯誤:語法錯誤,在<file>

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\baljeet2\ViewAllPolicy1.php on line 32

這裏是我的完整代碼:

<!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 

我還檢查發現,分號和語法,但一無所獲。

+8

'$ INT NUM_ROWS = 0;'是_not_有效的PHP。 –

+0

刪除int部分 –

+0

刪除'int'關鍵字,因爲PHP變量聲明不像C/C++/Java中那樣輸入。 –

回答

1

int是不是在PHP中的關鍵字。所以它將它解釋爲一個變量名。然後緊接着另一個變量名稱($num_rows),這是解析器不期望的。

我想你的意思是這樣的:

$num_rows = 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