<?php
include 'connection.php';
if(isset($_POST['val'])){
$a = $_POST['val'];
$sql = "SELECT * FROM car_details where id= '".$a."'";
$retval = mysql_query( $sql, $con );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
$ID = $row['ID'];
$Name = $row['Car_Name'];
$Category = $row['Category'];
$Transmision = $row['Transmision'];
$Seats = $row['seats'];
$EnginePower = $row['EnginePower'];
$EngineCapacity = $row['EngineCapacity'];
$MaxSpeed = $row['MaxSpeed'];
$TankCapacity = $row['TankCapacity'];
$Car_Details = $row['Car_Details'];
$img = $row['image_path'];
}
}
?>
它的php脚本从db获取数据,但它没有设置为html标记
<body>
<table id="car-tbl">
<div id="name"><center><h3><?php echo $Name; ?></h3></center></div><br />
<tr><td>Category</td><td> </td><td>Sport Car</td></tr>
<tr><td>Transmission</td><td> </td> <td>Automatic</td></tr>
<tr><td>Seats</td> <td> </td><td>2</td></tr>
<tr><td>Engine Power</td><td> </td> <td>420 hp</td></tr>
<tr><td>Engine Capacity</td> <td> </td><td>4200cc</td></tr>
<tr><td>Max Speed</td> <td> </td><td>301 km/h</td></tr>
<tr><td>Tank Capacity</td><td> </td><td>75 lt</td></tr>
<tr><td>GPS</td><td> </td><td>Yes</td></tr>
</table>
</body>
php脚本在html体外,我想在html表中添加这些PHP数据变量,因为你可以看到我已经在标签中实现了一些php代码,但它不起作用,但是它生成了它是未定义的变量
帮帮我
答案 0 :(得分:2)
请尝试以下代码
include 'connection.php';
if(isset($_POST['val'])){
$a = $_POST['val'];
$sql = "SELECT * FROM car_details where id= '".$a."'";
$retval = mysql_query( $sql, $con );
if(! $retval ) {
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
echo "<html><body><table id='car-tbl'><div id='name'><center><h3>";
echo $Name = $row['Car_Name'];
echo "</h3></center></div><br />";
echo "<tr><td>Category</td><td> </td>";
echo $Category = $row['Category'];
echo "</tr>";
echo "</table></body></html>";
}
}