mysql - search through a database using multiple keywords in php -



mysql - search through a database using multiple keywords in php -

i have page index.php has 3 keywords on basis of user can search database. code page is

<section id="services" class="emerald"> <div class="container"> <form class="form-horizontal" role="form" action="search.php" enctype="multipart/form-data" method="post"> <div class="row"> <div class="col-md-4 col-sm-6"> <div class="media"> <div class="media-body"> <?php $servername = "xyz.com"; $username = "xyz"; $password = "xyz123"; $dbname = "xyz"; // create connection $con = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$con) { die("connection failed: " . mysqli_connect_error()); } $sql = "select treatment_type treatment_type"; $result = $con->query($sql); echo "<label for='treatment_type'>treatment type: </label>"; echo "<select name='treatment_type' id='treatment_type' class='form-control'>"; while($row = $result->fetch_assoc()) { echo "<option value='" . $row['treatment_type'] . "'>" . $row['treatment_type'] . "</option>"; } echo "</select>"; ?> </div> </div> </div> <div class="col-md-4 col-sm-6"> <div class="media"> <div class="media-body"> <?php $servername = "xyz.com"; $username = "xyz"; $password = "xyz123"; $dbname = "xyz"; // create connection $con = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$con) { die("connection failed: " . mysqli_connect_error()); } $sql = "select course of study course"; $result = $con->query($sql); echo "<label for='course'>course/conference type: </label>"; echo "<select name='course' id='course' class='form-control'>"; while($row = $result->fetch_assoc()) { echo "<option value='" . $row['course'] . "'>" . $row['course'] . "</option>"; } echo "</select>"; ?> </div> </div> </div><!--/.col-md-4--> <div class="col-md-4 col-sm-6"> <div class="media-body"> <?php $servername = "xyz.com"; $username = "xyz"; $password = "xyz123"; $dbname = "xyz"; // create connection $con = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$con) { die("connection failed: " . mysqli_connect_error()); } $sql = "select facilities facilities"; $result = $con->query($sql); echo "<label for='facilities'>facilities: </label>"; echo "<select name='facilities' id='facilities' class='form-control'>"; while($row = $result->fetch_assoc()) { echo "<option value='" . $row['facilities'] . "'>" . $row['facilities'] . "</option>"; } echo "</select>"; ?> </div> </div> <div class="col-md-4 col-sm-6"> <div class="media-body"> <div class="col-md-8"> <input class="btn btn-primary" value="search" type="submit" name="submit"> </div> </div> </div> </div> </form> </div> </section>

code search.php

<?php error_reporting(0); $con=mysqli_connect("xyz.com","xyz","xyz123","xyz"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $treatment_type = mysqli_real_escape_string($con, $_post['treatment_type']); $course = mysqli_real_escape_string($con, $_post['course']); $facilities = mysqli_real_escape_string($con, $_post['facilities']); $sql1 = "select * office keywords '%$treatment_type' , '%$course' , '%$facilities'"; $result = mysqli_query($con, $sql1); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo "office name: " . $row["office_name"]. " - location: " . $row["office_address"]. " " . $row["office_city"]. "<br>"; } } else { echo "0 results"; } mysqli_close($con); ?>

what trying when user hits search link, user gets redirected page searchresult.php list of available details gets displayed. when run script getting value 0 results if value exists in database.

try query in searchresult.php

$sql1 = "select * office keywords '%$treatment_type%' or keywords '%$course%' or keywords '%$facilities%'";

php mysql sql mysqli

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -