2016-06-21 83 views
0

當我嘗試在HTML頁面中使用的「href」調用PHP文件的HTML MySQL表,我得到一個錯誤:連接到使用PHP

「解析錯誤:語法錯誤,意外‘>’在C: \ Program Files(x86)\ EasyPHP-DevServer-14.1VC9 \ data \ localweb \ 1.php on line 43「。

我不知道什麼是錯上線43,這裏是代碼:

<html> 
<head> 
<style> 
table, th, td { 
border: 1px solid black; 
} 
</style> 
</head> 
<body> 

<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "wt_database"; 

// Create connection 
$conn = new mysqli($servername, $username, $password, $dbname); 
// Check connection 
if ($conn->connect_error) { 
die("Connection failed: " . $conn->connect_error); 
} 

$sql = "SELECT cod, rated_power, max_output_power, output_voltage, generator_type, rotor_diameter, turbine_weight, design_lifetime, price FROM turbine_specs"; 
$result = $conn->query($sql); 

if ($result->num_rows > 0) { 
echo "<table> 
<tr> 
<th>Cod</th> 
<th>Rated Power</th> 
<th>Maximum Output Power</th> 
<th>Output Voltage</th> 
<th>Generator Type</th> 
<th>Rotor Diameter</th> 
<th>Turbine Weight</th> 
<th>Design Lifetime</th> 
<th>Price</th> 
</tr> 
// output data of each row 
while($row = $result->fetch_assoc()) { 
    echo " 
<tr> 
<td>" . $row["cod"]. "</td> 
<td>" . $row["rated_power"]. "</td> 
<td>" . $row["max_output_power"]. "</td> 
<td>" . $row["output_voltage"]. "</td> 
<td>" . $row["generator_type"]. "</td> 
<td>" . $row["rotor_diameter"]. "</td> 
<td>" . $row["turbine_weight"]. "</td> 
<td>" . $row["design_lifetime"]. "</td> 
<td>" . $row["price"]. "</td></tr> 

} 
echo "</table>"; 
} else { 
echo "0 results"; 
} 

$conn->close(); 
?> 

</body> 
</html> 

我包含此代碼的文件保存到我的「本地主機」文件夾作爲「.PHP」文件。

Image with containing titles of my mysql table

PS:很抱歉,如果我的英語不好。

PS2:我是初學者。

+0

查看此頁面上代碼中的語法顏色提示。注意什麼?具有彩色化的好IDE可以幫助您注意到這樣的錯誤。 – aynber

回答

0

在第39行,您需要用雙引號關閉。

echo "<table> 
<tr> 
<th>Cod</th> 
<th>Rated Power</th> 
<th>Maximum Output Power</th> 
<th>Output Voltage</th> 
<th>Generator Type</th> 
<th>Rotor Diameter</th> 
<th>Turbine Weight</th> 
<th>Design Lifetime</th> 
<th>Price</th> 
</tr>"; //you're missing the double quotation mark here, that's why you're getting the error. 
0

您錯過了關閉echo語句的雙引號。

echo "<table> 
<tr> 
<th>Cod</th> 
<th>Rated Power</th> 
<th>Maximum Output Power</th> 
<th>Output Voltage</th> 
<th>Generator Type</th> 
<th>Rotor Diameter</th> 
<th>Turbine Weight</th> 
<th>Design Lifetime</th> 
<th>Price</th> 
</tr>"; // correct this line/code