/这是我的代码,您认为我的代码中的问题是什么。部门不存在我的表格,所以我只给它一个值7。我想从部门的表格拨打7。$ res不执行。P>
$department = 7;
$depId = "SELECT * FROM departments";
$query_dept = mysql_query($depId, $conn);
$query_dept_results = mysql_fetch_array($query_dept);
if($query_dept_results['departmentId'] == $department) {
$id = $query_dept_results['departmentId'];
$query = "INSERT INTO suggestion (departmentId,name,address,barangay,message) VALUES('$id','$sfullname','$saddress','$sbarangay','$smessage')";
$res = mysql_query($query);
}
if ($res) {
$errTyp = "success";
$errMSG = "Sending successfully";
unset($sfullname);
unset($saddress);
unset($sbarangay);
unset($smessage);
header("Location:pupuntahan.php");
} else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
您的查询需要 where
子句。
$depId = "SELECT * FROM departments where departmentId = '$department'";
它将返回,该部门为7。
旁注: - security.database.sql-Inpotication