【发布时间】:2016-05-09 01:36:33
【问题描述】:
我的名字是 Luis,我正在尝试用 html、css 和 php 创建一个文件,该文件从数据库中获取信息并输出。但它必须与 html 位于同一页面中,以便我可以使用 CSS 进行编辑...谢谢大家!
<html>
<head>
</head>
<body>
<script>
</script>
<form action="<?php include 'file.php';?>" method="POST">
<b>Busque Jรก</b>
<input type="text" name="prestador" placeholder="prestador">
<input type="text" name="cidade" placeholder="cidade">
<input type="submit">
</form>
</body>
</html>
PHP 中的文件:
<?php
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "test";
$namer = $_POST['prestador'];
$cities = $_POST['cidade'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name,address,city FROM tb_prestadores WHERE name = '$namer' AND city = '$cities'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "name: " . $row['name']. " Endereço - : " . $row['address']." Cidade :".$row['city']."<br>";
}
} else {
echo "It is going to else";
}
$conn->close();
?>
【问题讨论】:
-
参考网络基础知识。将文件包含为
action值并不意味着该文件在您按下按钮时执行。 -
首先,恐怕这不是 php 的工作方式...您希望操作指向 file.php
<form action="./file.php"...>您正在执行的操作是打印文件的输出。 php 例如<form action="<?php include 'file.php';?>"变为<form action="It is going to else"