I have an input form where, when typing in a certain company's name (onkeyup), a color value is taken from an SQL database.
HTML:
<form id="changeForm" action="includes/tri-inc.php" method="post" style="width: 205px;">
<input id="hiddenId" type="hidden" name="verseid" value="23">
<input id="hiddenArea" type="hidden" name="hiddenArea" value="detail">
<input name="kategorie" type="text" placeholder="Kategorie" value="GA/MSRL"><br>
<input name="firma" onkeyup="showColor(this.value)" type="text" placeholder="Firmenname" value=""><br>
<input id="color" name="color" type="color" value="#FF22FF"><br>
<input name="person" type="text" placeholder="Kontaktperson" value=""><br>
<input name="adresse" type="text" placeholder="Adresse" value=""><br>
<input name="email" type="text" placeholder="Email-Adresse" value=""><br>
<input name="telefon" type="text" placeholder="Telefonnummer" value=""><br>
<input type="submit" name="submit">
</form>
javascript:
function showColor(str) {
if (str.length == 0) {
document.getElementById('color').value = "#808080";
return;
} else {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
document.getElementById("color").value = this.responseText;
}
xmlhttp.open("GET", "includes/getColor.php?c=" + encodeURIComponent(str));
xmlhttp.send();
}
}
PHP:
<?php
$c =$_REQUEST["c"];
require 'database.php';
if ($c !== "") {
$sql = "SELECT color FROM dreiecke WHERE firma = '" .urldecode($c). "'";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$result = $result[0];
echo $result === null ? "#ff22ff" : $result;
} else {
echo "#ff22ff";
}
?>
The command doesn't fire properly and returns the default #000000 to the value of the color input field.
The console reads: "mysqli_stmt_execute(): Property access is not allowed"
Where am I going wrong?