http://thpsblog.000webhostapp.com/aaDirectorio/index.html <- link to the index.html, it's in Spanish.
I'm following a tutorial on how to set up a Live Search Result because I'm trying to build a directory of "groups", it worked fine before I tried connecting to the database, so the jQuery I've tested and it has worked, it displays text when you type in more than 2 words, but when I tried to search for actual data inside this database, I couldn't get no results shown. I am using my code inside a file named 'backend' like:
backend.php
<?php
include 'db.inc.php';
if(isset($_POST['search'])){
$search = $_POST['search'];
$search = "%$search%";
if(strlen($search) > 2) {
$sql = "SELECT * FROM directorio_grupos_aa_sonora_sur WHERE grupo LIKE :s || ciudad LIKE :s || reuniones LIKE :s || direccion LIKE :s";
$stmt = $db->prepare($sql);
$stmt->bindParam('s',$search);
$stmt->excecute();
while($row = $stmt->fetch()){
$grupo = $row['grupo'];
$horario = $row['horario'];
$reuniones = $row['reuniones'];
$rsg = $row['rsg'];
$periodo = $row['periodo'];
$email = $row['email'];
$telefono = $row['telefono'];
$direccion = $row['direccion'];
$ciudad = $row['ciudad'];
echo "<div>$grupo $reuniones</p>$horario<br>$direccion<br>$ciudad<br>$rsg $telefono $periodo<br>
<a href='mailto;$email>$email</a></div>";
}
}
}
?>
while the 'db.inc.php' handles the connection to the database like:
<?php
try{
$db = new pdo('mysql:host=localhost;dbname=id9021430_directorio42;charset=utf8','id9021430_directorioaa', 'serviresvivir');}
catch(PDOException $e){die($e->getMessage());}
?>
and inside the index.html file, at least for the input side:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#search").keyup(function(){
$.ajax({
url: 'backend.php',
type: 'post',
data: {search: $(this).val()},
success:function(result){
$("#result").html(result);
}
});
});
});
</script>
<section class="container">
<div class="row">
<div class="col-lg-5">
<h2>Quick search</h2>
<p>Find groups: </p>
<input type="text" id="search" />
</p>
<span id="result"></span>
</div>
</div>
</section>
So, where could the problem be?