我尝试在表中进行简单的插入,但是我收到以下错误: SQLSTATE [HY093]:参数编号无效:参数未定义。我知道如果没有参数和匹配不相同,这个错误就会消失,但我一遍又一遍地检查它,我无法找到任何这样的不匹配。
我有 表中的列数:16 参数编号:16 没有比赛:16表格说明:
mysql> describe faculty;
+-----------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+-------------+------+-----+---------+-------+
| faculty_id | varchar(8) | NO | PRI | NULL | |
| faculty_name | text | NO | | NULL | |
| department_id | varchar(8) | YES | MUL | NULL | |
| department_name | varchar(8) | NO | | NULL | |
| profile_pic | text | NO | | NULL | |
| designation | text | NO | | NULL | |
| doj | date | NO | | NULL | |
| email | text | NO | | NULL | |
| highest_qualification | varchar(10) | YES | | NULL | |
| industrial_exp_yr | smallint(6) | YES | | NULL | |
| industrial_exp_month | smallint(6) | YES | | NULL | |
| teaching_exp_yr | smallint(6) | YES | | NULL | |
| teaching_exp_month | smallint(6) | YES | | NULL | |
| area_of_interest | text | NO | | NULL | |
| national_pub | smallint(6) | YES | | NULL | |
| international_pub | smallint(6) | YES | | NULL | |
+-----------------------+-------------+------+-----+---------+-------+
16行(0.01秒)
功能:
public function add_faculty($f_name, $f_department, $f_pic, $f_designation, $f_email, $f_doj, $f_qualification, $f_iExp_yr, $f_iExp_mth, $f_tExp_yr, $f_tExp_mth, $f_lPub, $f_iPub, $f_interest) {
try {
$facul_id = $this -> get_facultyID();
$dept_id = $this -> get_DeptID($f_department);
$db = new PDO(DB_CONN, DB_USER, DB_PASS);
$db -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db -> setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$query = "insert into faculty (faculty_id , faculty_name , department_id , department_name ,profile_pic , designation , doj , email , highest_qualification , industrial_exp_yr ,industrial_exp_month , teaching_exp_yr , teaching_exp_month ,
area_of_interest , national_pub , international_pub) values (:facul_id , :f_name , :dept_id , :dept_name , :f_pic , :f_designation , :f_doj , :f_email , :f_qualification , f_iyr ,:f_imth , :ftyr , :ftmth , :finterest , :flpub , :fipub);";
$stmt = $db -> prepare($query);
$stmt -> bindParam(':facul_id', $facul_id, PDO::PARAM_STR);
$stmt -> bindParam(':f_name', $f_name, PDO::PARAM_STR);
$stmt -> bindParam(':dept_id', $dept_id, PDO::PARAM_STR);
$stmt -> bindParam(':dept_name', $f_department, PDO::PARAM_STR);
$stmt -> bindParam(':f_pic', $f_pic, PDO::PARAM_STR);
$stmt -> bindParam(':f_designation', $f_designation, PDO::PARAM_STR);
$stmt -> bindParam(':f_doj', $f_doj, PDO::PARAM_STR);
$stmt -> bindParam(':f_email', $f_email, PDO::PARAM_STR);
$stmt -> bindParam(':f_qualification', $f_qualification, PDO::PARAM_STR);
$stmt -> bindParam(':f_iyr', $f_iExp_yr, PDO::PARAM_INT);
$stmt -> bindParam(':f_imth', $f_iExp_mth, PDO::PARAM_INT);
$stmt -> bindParam(':f_tyr', $f_tExp_yr, PDO::PARAM_INT);
$stmt -> bindParam(':f_tmth', $f_tExp_mth, PDO::PARAM_INT);
$stmt -> bindParam(':finterest', $f_interest, PDO::PARAM_STR);
$stmt -> bindParam(':flpub', $f_lPub, PDO::PARAM_INT);
$stmt -> bindParam(':fipub', $f_iPub, PDO::PARAM_INT);
$stmt -> execute();
if ($stmt -> rowCount() > 0) {
$utils = new utils();
$admin_id = $utils -> session_user_id();
$utils -> log_admin($admin_id, "New faculty Profile Created - " .$f_name);
return true;
} else {
return false;
}
} catch (PDOException $ex) {
echo $ex -> getMessage();
//utils::log_error($ex -> getMessage());
}
}
请帮我弄清楚错误。我现在已经上了几个小时了。我知道这可能是我无法发现的愚蠢行为。如果您需要更多详细信息,请与我们联系。
答案 0 :(得分:3)
$stmt -> bindParam(':f_tyr', $f_tExp_yr, PDO::PARAM_INT);
$stmt -> bindParam(':f_tmth', $f_tExp_mth, PDO::PARAM_INT);
代码。
这导致这些参数没有价值。
答案 1 :(得分:1)
您在声明中:
param之前忘记了f_iyr
。
$query = "insert into faculty (faculty_id , faculty_name , department_id , department_name ,profile_pic , designation , doj , email , highest_qualification , industrial_exp_yr ,industrial_exp_month , teaching_exp_yr , teaching_exp_month ,
area_of_interest , national_pub , international_pub) values (:facul_id , :f_name , :dept_id , :dept_name , :f_pic , :f_designation , :f_doj , :f_email , :f_qualification , :f_iyr ,:f_imth , :ftyr , :ftmth , :finterest , :flpub , :fipub);";
另外:ftyr
,:ftmth
未设置