I have been getting an internal server error 500 for 8 days now and cannot find a way to solve it.
I want to make a search option for my users (when i get them, lol). I tried $.POST
method alone, yesterday I changed it to $.ajax
post method, and got the same results.
I think the error is coming from the URL properties. I tested every line of code and it does work, but when I go to URL everything goes to hell... Every time I put something different than "/wp-content/themes/yuuta/Food-Groups-BG.php"
as my file path I get 404 NOT FOUND
and when I put it back I get 500 internal server error
... I had read every post that I could find on the internet and have tried many solutions and it won't work... :X
Here is my JQuery and PHP.
jQuery(document).ready(function ($) {
$("#food_search").keyup(function(event){
var search_term =$(this).val();
$.ajax({
type:"POST",
url:"/wp-content/themes/yuuta/Food-Groups-BG.php",
data:{fsearch:search_term},
success:function(res){
$("#food_search_result").html(res);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<p>Търсене на храни: <input type="text" name="food-search" id="food_search"></p>
<!----------------------------------------------------------------
PHP
----------------------------------------------------------------->
<?php
$hostname = "localhost";
$username = "myName";
$password = "myPassword";
$databaseName = "dbName";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
if(isset($_POST['Title']) && $_POST['Title']!=""){
$fsearch = $connect->prepare("SELECT * FROM food_data_bg WHERE title LIKE :Title");
$fsearch->execute(array(
'Title'=>'%'.$_POST['Title'].'%'
));
if($fsearch->rowCount()==0){
echo 'Не бяха намерени резултати!';
}
else{
while($data=$fseach->fetch()){
?>
<div class="search-result">
<img src="<?php echo $data['fimage']; ?>" class="fimage"/>
<span class="result-title"><?php echo $data['title'];?></span><br>
<span class="calories-total"><?php echo $data['calories total'];?></span><br>
</div>
<?php
}
}
}else
{
echo 'Напишете име на продукт!';
}
?>