Ich möchte Daten aus MySQL-Tabelle suchen und abrufen. Ich benutzte zwei Textfelder, um Suchbegriffe zu erhalten. Ich habe dafür Jquery Ajax benutzt. Zum ersten Mal habe ich nur den Ort für die Suche benutzt. Dann funktioniert es. Wenn ich beide Textfelder benutzte, funktionierte es nicht. Dann bekam ich immer no data
.Suchfunktion mit zwei Textfield-Daten in Jquery Ajax
<div class="container">
<form action="search.php" method="post">
<input type="text" id="location" name="location">
<input type="text" id="catogary" name="catogary">
<script>
$('#location,#catogary').keyup(function() {
var loca=$(this).val();
var cato=$(this).val();
if(loca!='' || cato!=''){
$.ajax({
url:"search.php",
method:"POST",
data:{searc:loca,cato:cato},
DataType:"text",
success:function (data) {
$('#result').html(data);
}
});
}
else{
$('#result').html('');
}
});
</script>
</form>
<div id="result"></div>
</div>
PHP-Code
<?php
$conn=mysqli_connect("localhost","root","","internship");
$output='';
$sql="select * from vacancy where location like '%".$_POST["searc"]."%'
and catogary like '%".$_POST["cato"]."%'";
$res=mysqli_query($conn,$sql);
if(mysqli_num_rows($res)>0){
while($row=mysqli_fetch_assoc($res)){
?>
<div class="bs-calltoaction bs-calltoaction-primary">
<div class="row">
<div class="col-md-9 cta-contents">
<h1 class="cta-title">Its a Call To Action</h1>
<div class="cta-desc">
<input type="text" value='<?= $row['catogary'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['company_name'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['location'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['qulification'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['catogary'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['indate'];?>' readonly style="width: 37.5%">
<input type="text" value='<?= $row['expdate'];?>' readonly style="width: 37.5%">
</div>
</div>
<div class="col-md-3 cta-button">
<a class="btn btn-primary btn-large"
href="#myModal" data-toggle="modal">Apply for job</a>
</div>
</div>
</div>
<?php
}
}
else{
echo 'no data';
}
?>
Sie möglicherweise nicht die Daten, die erfüllt auch die Voraussetzungen sowohl bekommen Werte nicht post-Daten direkt in Abfrage verwenden, sanieren und und validieren und dann verwenden. –
In Ihrem Ajax-Aufruf setzen Sie sowohl loca als auch cato auf dasselbe, nicht auf die Werte der beiden Felder. –