我需要使用substr来获取已写信的姓名,或者我是否写了名称的一部分
if(isset($_GET['search'])){
$sql="SELECT * FROM students WHERE first_name='".$_POST['sname']."' OR last_name='".$_POST['fname']."'";
$record=mysql_query($sql);}
<?php
echo"<form action='admin.php?page=3&search' method='Post'>";
echo"<input type='text' name='sname' value='ex: Student Name'> ";
echo"<input type='text' name='fname' value='ex: Family Name'> ";
echo"<button type='submit' name='search' class='btn' >Search</button>";
echo"</form>";
?>
答案 0 :(得分:1)
我认为您需要更改查询,在查询中使用LIKE
:
$sql="SELECT * FROM students WHERE first_name like '%".$_POST['sname']."%' OR last_name like '%".$_POST['fname']."%' ";
答案 1 :(得分:1)
使用LIKE %
。
if(isset($_GET['search']))
{
$sql="SELECT * FROM students WHERE first_name LIKE '%".$_POST['sname']."%' OR last_name LIKE '%".$_POST['fname']."%'";
$record=mysql_query($sql);
}