Here is the php (database is set up correctly):
include_once 'dbh.inc.php';
$data = "";
if(isset($_GET['q'])){
$data = $_GET['q'];
}
$sqlSearch = "SELECT * FROM `brsinks` WHERE `name` LIKE '%$data%'";
$resultSearch = mysqli_query($conn, $sqlSearch);
if($resultSearch){
if(empty($resultSearch)){
echo "empty results";
}
else{
foreach($resultSearch as $result){
echo <<<HTML
<div class="productContainer">
<img src="none" alt="productIMG" class="prodIMG">
<a class="prodNAME" href="none">$result['name']</a>
<div class="prodPRICEsku">
<p class="prodPRICE">
result
</p>
<p class="prodSKU">
result
</p>
</div>
<button class="prodADD" id="prodADD">+</button>
</div>
HTML;
}
}
}
else {
echo "error";
}
here is my javascript(for XML req and res):
function updateResults(x){
const resultsNumDisplay = document.getElementById('searchResultsDisplay');
const resultsDisplay = document.getElementById('productsActualScreenDisplay')
if(x == ''){
resultsDisplay.innerText = 'empty...'
} else {
var XML = new XMLHttpRequest();
XML.onreadystatechange = function(){
if(XML.readyState == 4 && XML.status == 200){
resultsDisplay.innerHTML = XML.responseText;
console.log(XML.responseText);
}
};
XML.open('GET', 'includes/searchFunctions.inc.php?q=' + x, true);
XML.send();
XML.DONE;
}
}
the parameter on updateResponse(x <-)
is passed inline from html onkeyup="updateResponse(this.value)"
.
My issue is that when I try to get the value of $result['name']
the XML response code is 500 (internal server error). But when i just put dummy values like result
it returns the correct amount of items as I type (example I type 'blue' -> 5 divs appear) but I just cant seem to get the individual name value in the for each loop which I usually can In normal php/html code.
What Im looking to know:
is there an alternative to getting the value of a returned row within a foreach loop?