我正在使用php创建一个网页,在这个页面我必须使用php搜索起始地点到交付地点的详细信息这可能吗?
我的代码如下:
的index.php
<form id="contactForm" action="index.php" novalidate>
<label>Starting Place</label>
<input type="text" name="starting_place" placeholder="Enter Starting Place">
<label>Starting Place</label>
<input type="text" name="delivery_place" placeholder="Enter Starting Place">
<input type="submit" name="search" value="search">
</form>
<?php
include 'db.php';
if(isset($_POST['search']))
{
$sql = mysql_query("select * from place where "); // this is my question
while($row = mysql_fetch_array($sql))
{
echo $row['starting_place'];
echo $row['delivery_place'];
}
}
?>
答案 0 :(得分:0)
我认为你的查询不好
$sql =mysql_query("select * from place where ");
也许你会这样做
$search = $_POST['search'];
$sql =mysql_query("select * from `place` where `starting_place` = '$search' ");
完整的PHP代码
include 'db.php';
if(isset($_POST['search']))
{
$search = $_POST['search'];
$sql =mysql_query("select * from `place` where `starting_place` = '$search' ");
while($row = mysql_fetch_array($sql))
{
echo $row['starting_place'];
echo $row['delivery_place'];
}
}
答案 1 :(得分:0)
mysql_*
已被弃用,请使用mysqli _ * or
pdo`而不是
检查此查询:
$start = $_POST['starting_place'];
$end = $_POST['delivery_place'];
$sql = mysql_query("select * from place where starting_place = $start and ending_place = $end ");
答案 2 :(得分:0)
你的问题不是很清楚。我假设你只有一个输入字段:
<form id="contactForm" action="index.php" novalidate>
<label>Starting Place</label>
<input type="text" name="starting_place" placeholder="Enter Starting Place">
<input type="submit" name="search" value="search">
</form>
然后,您的PHP代码应如下所示:
$starting_place = $_POST['starting_place']; //name of your input box
if (isset($starting_place)) {
$sql = mysql_query("select * from place where place='" . $starting_place . "'");
while($row = mysql_fetch_array($sql)) {
echo $row['starting_place'];
echo $row['delivery_place'];
}
}