Reputation: 5
i need to use substr to get the name who have written letters or if i write a part of the name
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>";
?>
Upvotes: 0
Views: 90
Reputation: 2234
I think you need to change the query, Use LIKE
in the query:
$sql="SELECT * FROM students WHERE first_name like '%".$_POST['sname']."%' OR last_name like '%".$_POST['fname']."%' ";
Upvotes: 1
Reputation: 4166
Use 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);
}
Upvotes: 1