我使用搜索表单来搜索与数据基础值,但我没能得到充分利用PHP中存储的数据的基础数据结果我的表名是数据基础“用户”请帮助如何使用搜索框
data.html 我的代码看起来像
<form action="data2.php" class="navbar-form navbar-right">
<div class="input-group">
<input type="Search" name="user_search" value="" placeholder="Search..." class="form-control" />
<div class="input-group-btn">
<button class="btn btn-info">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
</form>
现在
我data2.php类似的代码
<?php
include("db/opendb.php");
$username=$_POST['user_search'];
$query = "SELECT * FROM user WHERE user_name=='" .$username"'";
$result = $conn ->query($query) or die("Query error");s
?>
<table width="983" border="1" cellpadding="5" class="insertTable">
<tr>
<td width="50"><strong>user id</strong></td>
<td width="109"><strong>user name</strong></td>
<td width="40"><strong>user adress</strong></td>
<td width="38"><strong>user phone no</strong></td>
<td width="99"><strong>dept id</strong></td>
</tr>
<?php
foreach($result as $row)
{
?>
<tr>
<td><?php echo $row['user_name']; ?></td>
<td><?php echo $row['user_adress']; ?></td>
<td><?php echo $row['user_phone_no']; ?></td>
<td><?php echo $row['dept_id']; ?></td>
</tr>
<?php
}
?>
请任何机构可以帮助我,我正在努力工作,但没有什么好办法结果不显示 我正在使用搜索表单来搜索数据库中的值,但我没有得到结果我的表名称是数据库中的“用户”请帮助 我会对你非常满意
'其中user ==''一个'=这里也和许多失踪' ' “$用户名”''点。检查错误将避免这种调试/错字问题。并在这里''或死(“查询错误”); s'不应该在那里。 –
感谢它现在的工作 –
不客气。我发布了一个可以接受的(社区维基)答案,以便将问题标记为已解决。请参阅http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work关于如何做到这一点。 –