当我按下我的html页面上的搜索按钮时,它会在我的桌子上添加一辆新车,但我希望能够从我在MySql上创建的汽车列表中搜索汽车。我有一个car_displayed代码,一旦搜索到位,它将在一个表格中显示汽车。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="description" content="Searing for a car" />
<meta name="keywords" content="PHP, MySql" />
<title>Retrieving records to HTML</title>
</head>
<body>
<h1>Car Search</h1>
<?php
require_once ("settings.php"); //connection info
$conn = @mysqli_connect($host,
$user,
$pwd,
$sql_db
);
$make = trim($_POST["carmake"]);
$model = trim($_POST["carmodel"]);
$price = trim($_POST["price"]);
$yom = trim($_POST["yom"]);
$sql_table="cars";
$query = "insert into $sql_table (make, model, price) values ('$make', '$model', '$price')";
//execute the query -we should really check to see if the batabase exists first.
$result = mysqli_query($conn, $query);
//checks if the exeution was succcessful
if (!$result) {
echo "<p class=\"wrong\">Something is wrong with ", $query, "</p>";
// would not show in a production script
} else {
// display an operation successful message
echo "<p class=\"ok\">Successfully Searched Car record</p>";
} // if successful query operation
// close the database connection
mysqli_close($conn);
// if successful database connection
?>
</body>
</html>
答案 0 :(得分:0)
不是插入新车,而是使用像
这样的'select`查询来查找 $query = "select model, price from $sql_table where make LIKE %$make%"
执行后,$result
将包含所请求的信息。
PS:我猜测make
是你桌上的主键。