2016-06-21 72 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