Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Search Box</title>
- <link rel="stylesheet" href="style.css" type="text/css">
- </head>
- <body>
- <form action="" method="POST" id="searchForm">
- <input type="text" name="q" id="searchBar" placeholder="Search..." maxlength="25">
- <input type="submit" id="searchBtn" value="Go">
- </form>
- <?php
- if(isset($_POST['q']))
- {
- if(trim($_POST['q'])!='')
- {
- $con = mysqli_connect('localhost','root','','search');
- $prep=mysqli_stmt_init($con);
- mysqli_stmt_prepare($prep, "SELECT id, title, description FROM products WHERE title LIKE ? OR description LIKE ?");
- $q='%'.$_POST['q'].'%';
- mysqli_stmt_bind_param($prep, "ss", $q, $q);
- mysqli_stmt_execute($prep);
- mysqli_stmt_store_result($prep);
- $num_rows = mysqli_stmt_num_rows($prep);
- ?>
- <p><strong><?php echo $num_rows; ?></strong> results for '<?php echo htmlspecialchars($_POST['q']); ?>'</p>
- <?php
- if($num_rows!=0)
- {
- mysqli_stmt_bind_result($prep, $id, $title, $desc);
- while(mysqli_stmt_fetch($prep))
- {
- echo '<h3><a href="termek.php?id='.$id.'">'.$title.'</a><h3><p>'.nl2br($desc).'</p><br>';
- }
- }
- mysqli_stmt_close($prep);
- }
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment