0

When i try to call a php file using "href" in a html page, i get an error:

"Parse error: syntax error, unexpected '>' in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\1.php on line 43".

I don't know what is wrong on line 43, here is the code:

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

I saved the file containing this code into my "localhost" folder as a ".php" file.

Image with containing titles of my mysql table

PS:Sorry if my english is bad.

PS2:I am a beginner.

  • Check out the syntax color hints in your code on this page. Notice anything? A good IDE with colorization can help with noticing errors like this. – aynber Jun 21 '16 at 18:32

2 Answers2

0

On line 39 you need to close with double quotation mark.

 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. 
unixmiah
  • 3,081
  • 1
  • 12
  • 26
0

You missed double quotes for closing echo statement.

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
Ravinder Reddy
  • 3,869
  • 1
  • 13
  • 22