我收到此错误
警告:试图访问第15行E:\xampp\htdocs\word-meaning-learn\word-ajax-insert.php中类型为null的值的数组偏移量插入了含义数据!
行上的代码有什么问题?〉if($row['bangla_mean'] == $bangla_mean)
<?php
include "config.php";
$bangla_mean = $_POST["bangla_mean"];
$english_mean = $_POST["english_mean"];
$example_mean = $_POST["example_mean"];
$synonym_mean = $_POST["synonym_mean"];
if(isset($bangla_mean)){
$stmt = $conn->prepare("SELECT bangla_mean FROM wordmeanings_table WHERE bangla_mean=?");
$stmt->bind_param("s",$bangla_mean);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array(MYSQLI_ASSOC);
if($row['bangla_mean'] == $bangla_mean){
$response = "This Bangla meaning already exist!";
}
else{
$stmt = $conn->prepare("INSERT INTO wordmeanings_table (bangla_mean, english_mean, example_mean, synonym_mean) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss",$bangla_mean,$english_mean,$example_mean,$synonym_mean);
if($stmt->execute()){
$response = "Inserted the meaning data!";
}
else{
$response = "Something went wrong!";
}
}
}
echo $response;
exit;
?>
2条答案
按热度按时间uklbhaso1#
错误消息表示
$row
变量为空,但您试图将其视为数组。当未找到行时,fetch_array()
方法的法律的返回值为空。如果找到行,方法将从POST中为请求的“bangla_mean”返回关联数组。或者检查
$row
不为空的另一个选项:e0bqpujr2#
你的查询是空的,你试图得到的结果是“?",这是不符合逻辑的..尝试这样做: