我想要做的是将一个名称放入输入类型框并按提交,一旦提交Id,就像它只显示所有相同的名称行而不是数据库中的所有名称?任何人都可以帮助我尝试或||在PHP但只获得所有结果?
<form method="post" action="">
<label for="name">Name:</label>
<input type="text" name="name" id="name" />
<button onclick="refreshMap()">Refresh</button>
</form>
function refreshMap() {
var name = $('#name').val();
}
<script>
$(function() {
$('#name').val(name);
});
</script>
PHP:
$query = "SELECT * FROM register WHERE name IN ('John' || 'Gina')";
$result = mysql_query($query);
if($result === FALSE) {
die(mysql_error());
}
if(!empty($_POST['name']))
{
while($row = mysql_fetch_array($result)){
echo $row['name'];
}
}
答案 0 :(得分:2)
修改强>
$name = htmlspecialchars($_POST['name']);
if(!empty($name))
{
$query = "SELECT * FROM register WHERE name LIKE '" .$name ."'";
$result = mysql_query($query);
if($result === FALSE) {
die(mysql_error());
exit(0);
}
while($row = mysql_fetch_array($result)){
echo $row['name'];
}
}