我正在尝试使用mysqli_query,但我的查询似乎有问题而且我不知道在哪里。
adminhostelryadd.php
<?php
include '../connection/connect.php';
$adminhostelryform = json_decode(file_get_contents("php://input"));
$data = array();
$emptyform = false;
$validateusername = false;
$usernamelength = false;
$passwordlength = false;
$querysuccess = false;
$hostelryqueryname = $adminhostelryform->hostelryname;
$hostelryquerytype = $adminhostelryform->hostelrytype;
$hostelryquerydescription = $adminhostelryform->hostelrydescription;
$hostelryqueryusername = $adminhostelryform->hostelryusername;
$hostelryquerypassword = $adminhostelryform->hostelrypassword;
if(isset($hostelryqueryname) && isset($hostelryquerytype) && isset($hostelryquerydescription) && isset($hostelryqueryusername) && isset($hostelryquerypassword)) {
if(empty($hostelryqueryname) && empty($hostelryquerytype) && empty($hostelryquerydescription) && empty($hostelryqueryusername) && empty($hostelryquerypassword)) {
$emptyform = true;
} else {
$checkusername = mysqli_query($conn, "SELECT hostelry_username FROM hostelryacc WHERE hostelry_username='$hostelryqueryname'");
$validate = mysqli_num_rows($checkusername);
if($validate) {
$validateusername = true;
} else {
if(strlen($hostelryqueryusername) < 5) {
$usernamelength = true;
} else if(strlen($hostelryquerypassword) < 5) {
$passwordlength = true;
} else {
$id = "ADMINHOSTELRY-" . rand(10, 100) . "-" . rand();
$query = mysqli_query($conn, "INSERT INTO hostelryacc VALUES('$id', '$hostelryqueryname', '$hostelryquerytype', '$hostelryquerydescription', '$hostelryqueryusername', '$hostelryquerypassword')");
if($query) {
$querysuccess = false;
} else {
$querysuccess = true;
}
}
}
}
}
$data["emptyform"] = $emptyform;
$data["validateusername"] = $validateusername;
$data["usernamelength"] = $usernamelength;
$data["passwordlength"] = $passwordlength;
$data["querysuccess"] = $querysuccess;
echo json_encode($data);
?>
我的$ query = mysqli_query出现了问题($ conn,&#34; INSERT INTO hostelryacc VALUES(&#39; $ id&#39;,&#39; $ hostelryqueryname&#39;,&#39; $ hostelryquerytype&#39;, &#39; $ hostelryquerydescription&#39;,&#39; $ hostelryqueryusername&#39;, &#39; $ hostelryquerypassword&#39;)&#34);