php sql search form


<?php
$localhost = "localhost";
$username = "root";
$password = "";
$dbname = "samueldb";
$con = new mysqli($localhost, $username, $password, $dbname);
if( $con->connect_error){
    die('Error: ' . $con->connect_error);
}
$sql = "SELECT * FROM users";
if( isset($_GET['search']) ){
    $name = mysqli_real_escape_string($con, htmlspecialchars($_GET['search']));
    $sql = "SELECT * FROM users WHERE firstname ='$name'";
}
$result = $con->query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>Basic Search form using mysqli</title>
<link rel="stylesheet" type="text/css"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<label>Search</label>
<form action="" method="GET">
<input type="text" placeholder="Type the name here" name="search"> 
<input type="submit" value="Search" name="btn" class="btn btn-sm btn-primary">
</form>
<h2>List of students</h2>
<table class="table table-striped table-responsive">
<tr>
<th>ID</th>
<th>First name</th>
<th>Lastname</th>
<th>Address</th>
<th>Contact</th>
</tr>
<?php
while($row = $result->fetch_assoc()){
    ?>
    <tr>
    <td><?php echo $row['user_id']; ?></td>
    <td><?php echo $row['firstname']; ?></td>
    <td><?php echo $row['lastname']; ?></td>
    <td><?php echo $row['address']; ?></td>
    <td><?php echo $row['contact']; ?></td>
    </tr>
    <?php
}
?>
</table>
</div>
</body>
</html>

0
3
Phoenix Logan 186120 points

                                    $result = mysqli_query($con, &quot;SELECT * FROM employees
    WHERE first_name LIKE '%{$name}%' OR last_name LIKE '%{$name}%'&quot;);

while ($row = mysqli_fetch_array($result))
{
        echo $row['first_name'] . &quot; &quot; . $row['last_name'];
        echo &quot;&lt;br&gt;&quot;;
}
    mysqli_close($con);
    ?&gt;

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to take data from search form in php simple search query in php simplest way to make mysql search in php how to create search query in php search php mysql example php get search sql php sql search bar php sql search query in php strom select and search search in php and mysql search in mysql php search data containing 's in sql php search query in in db php php sqlsrv searching search php sql database form search php sql database mysql php search query search in query result php search results php php mysql search form display search results of sql query php search with php and mysql search results in php code search from form php query for search php search bar query in php mysql search query php how to display search result in a form in php search php mysql php sql search when PHP MySQL search form example how to create search form in php search from database in php php mysql search query example php mysql search query php search from database how to make a search field in php simple search field php how to search in sql database table php simple search form in php how to create basic php search w sql search bar with query php sql and php search statement mysql search in php php search form select sql php search search bar php sql search inside php files search in php mysql php search query from form php search query search in form php php sql statement search field with ' search form with php php mysql search search query php and sql search query php php search from my sql search results.php search query in php search in database in php form search php sqlsrv search in php mysql with examples search query in sql using php php search in database sql search php search form php mysql database php search page example php search database with search bar search sql php form search sql php search in sql php php search bar mysql php search from database table Searches related to php code search within php page mysql search html search data in form within php page search form within php page search form in php page Search form in php search from in php how to create a search query in php php sql search form search in all fields from a table sql in php php search form php search database with form php serach function search php search form php mysql search function php search user page php search user php how to make a search form to search a record from list in php how to create search by category in html with database search in php use search form php serach in php how to make search in database php seach from php by name by search input search by name php code php search how to search for name in database which is input in html form How to create a search form using PHP how to search through html using php search form php php search form search using php
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source