提问人:Lukas 提问时间:8/23/2021 更新时间:8/25/2021 访问量:49
Ajax 请求返回“mysqli_stmt_execute():不允许属性访问”
Ajax request returns "mysqli_stmt_execute(): Property access is not allowed"
问:
我有一个输入表单,其中输入某个公司的名称 (onkeyup) 时,会从 SQL 数据库中获取颜色值。
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";
}
?>
该命令无法正确触发,并将默认的 #000000 返回到颜色输入字段的值。
控制台显示:“mysqli_stmt_execute():不允许属性访问”
我哪里出错了?
答:
0赞
Lukas
8/25/2021
#1
多亏了 Dharman 的评论,我设法弄清楚了:
<?php
$c =$_REQUEST["c"];
require 'database.php';
$defaultColor = "@808080";
if ($c !== "") {
$c = urldecode($c);
$stmt = $conn->prepare("SELECT color FROM dreiecke WHERE firma=?");
$stmt->bind_param("s", $c);
$stmt->execute();
$stmt->bind_result($result);
$stmt->fetch();
$result = substr($result, 0, 7);
if ($result != null) {
echo $result == null ? "#ffffff" : $result;
}
return;
}
echo $defaultColor;
?>
评论
prepare