我希望从我的下拉列表中获取值,并将其与我的departmentId行进行比较,因此在生成报告时,我只需从departments表中调用departmendId行即可。
<div class="form-group category">
<label for="category">Departamento: </label>
<select class="form-control form-element" name='department'>
<option selected disabled> --Piliin ang Departamento-- </option>
<h3><optgroup label="ADMINISTRATIVE SERVICES">
<option class='drop-down' value='1'> Office of the City Mayor </option>
<option class='drop-down' value='2'> Office of the City Administrator </option>
<option class='drop-down' value='3'> Human Resources Management Office </option>
<option class='drop-down' value='4'> Central Records Management Office </option>
<option class='drop-down' value='5'> General Services Office </option>
<option class='drop-down' value='6'> Procurement Office
</option>
<option class='drop-down' value='7'> Public Information Office </option>
<option class='drop-down' value='8'> Anti-Graft Board </option>
</optgroup>
</select>
</div>//这是我的下拉列表
if (isset($_GET['department']))
{
$department=$_GET['department'];
}//这是我从dropdown获取值的代码
$depId = "SELECT FROM departments WHERE 'departmentId' = $department";
$result = mysql_query($depId);
if($department == $result) {
$query = "INSERT INTO complain (department,name,address,barangay,complainee,subject,message) VALUES('$result','$fullname','$address','$barangay','$complainee','$subject','$message')";
$res = mysql_query($query);
}//这是我将dropdown的值与departmentId行进行比较时的代码,departmentId的值必须在抱怨表的部门行中,当我查看我的抱怨表部门行时,它什么也没有显示。
发布于 2017-02-28 13:02:30
第一个正确的SQL SELECT查询必须是
SELECT * FROM departments WHERE departmentId = $department;然后,您需要使用mysqli_fetch()语句之一获取departmentId的值,最后将其与下面的$department.As进行比较。
$depId = "SELECT * FROM departments WHERE departmentId = $department"
$result = mysqli_query($connection,$depId);//$connection is database connection object
while($row = mysqli_fetch_assoc($result)){
if($department == $row['departmentId']) {
$fullname = $row['fullname'];
$address = $row['address'];
$barangay = $row['barangay'];
$complainee = $row['complainee'];
$subject = $row['subject'];
$message = $row['message'];
$query = "INSERT INTO complain (department,name,address,barangay,complainee,subject,message) VALUES('$department','$fullname','$address','$barangay','$complainee','$subject','$message')";
mysqli_query($connection,$query);
}
}发布于 2017-02-28 12:51:54
您在查询中遇到更改select查询问题,如下所示:
SELECT *
FROM departments
WHERE departmentId = $department;发布于 2017-02-28 12:52:55
更改此行:
$depId = "SELECT FROM departments WHERE 'departmentId' = $department";使用
$depId = "SELECT * FROM departments WHERE departmentId = '$department'";使用
var_dump(...);die();为了方便起见,您的代码的每一层。例如:
$depId = "SELECT * FROM departments WHERE 'departmentId' = $department";
var_dump($depId);die();https://stackoverflow.com/questions/42500366
复制相似问题