我不知道如何将此 $_POST 转换为字符串并将其分配给变量而不是数组。是否有像 C# 中的 Convert.ToString(RadioButtonValue) ?我想在我的 SQL 语句中使用该变量作为参数。
$DeptCode = $_POST['Department'];
print_r($DeptCode);
$sql = "SELECT EMPLOYEE.EmpID, EmpName FROM EMPLOYEE, EMPLOYEE_SPECIALIZATION WHERE EMPLOYEE.EmpID = EMPLOYEE_SPECIALIZATION.EmpID AND EmpStatus='active' AND DeptCode = '$DeptCode'";
$results = mysql_query($sql,$con);
if($results != $sql)
{
die('Error' . mysql_error());
}
这是我的 SQL 语句。我究竟做错了什么?
$sql = "SELECT EMPLOYEE.EmpID, EmpName FROM EMPLOYEE, EMPLOYEE_SPECIALIZATION WHERE EMPLOYEE.EmpID = EMPLOYEE_SPECIALIZATION.EmpID AND EmpStatus='active' AND DeptCode = '$DeptCode'";
当我运行它时......它总是显示
Array ( [0] => PD ) Error
这是整个代码:
<html>
<head>
<title>New Checkup</title>
</head>
<body>
<h1><a href="http://localhost/clinic/InsertPatient.php">Insert Patient</a></h1><br>
<h1><a href="http://localhost/clinic/InsertEmployee.php">Insert Doctor and Specialization</a></h1>
<h1><a href="http://localhost/clinic/InsertProcedureHTML.php">Insert Products and Services</a></h1>
<h1><a href="http://localhost/clinic/NewCheckup.php">New Checkup</a></h1>
<form method="post">
<?php
//action="http://localhost/clinic/NewCheckup2.php"
$con = mysql_connect('localhost', 'root', "");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_clinic", $con) or die(mysql_error());
$sql = "SELECT DeptCode, DeptName FROM DEPARTMENT";
$results = mysql_query($sql,$con);
while($row=mysql_fetch_assoc($results))
{
echo "<input type='radio' name='Department[]' value='".$row['DeptCode']."'>".$row['DeptName'];
}
mysql_close($con);
?>
<input type="submit" name="btnSubmit">
</form>
<?php
if(isset($_POST['btnSubmit']))
{
$con = mysql_connect('localhost', 'root', "");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_clinic", $con) or die(mysql_error());
$DeptCode = $_POST['Department'];
print_r($DeptCode);
echo $DeptCode;
$sql = "SELECT EMPLOYEE.EmpID, EmpName FROM EMPLOYEE, EMPLOYEE_SPECIALIZATION WHERE EMPLOYEE.EmpID = EMPLOYEE_SPECIALIZATION.EmpID AND EmpStatus='active' AND DeptCode = '$DeptCode'";
$results = mysql_query($sql,$con);
if($results != $sql)
{
die('Error' . mysql_error());
}
mysql_close($con);
}
?>
</body>