这是我的receptionistAction.php文件,可以让我操作表单的crud函数。
我正在尝试将接待员及其用户信息插入到不同的SQL语句中,但这会导致系统出错。
<?php
session_start();
include '../../dbConnect.php';
$pdo = new dbConnect();
$tblName = 'receptionist';
$tblName2 = 'users';
if(isset($_REQUEST['action_type'])!empty($_REQUEST['action_type'])){
if($_REQUEST['action_type'] == 'add'){
$userData = array(
'Rec_lastName' => $_POST['rlname'],
'Rec_firstName' => $_POST['rfname'],
'Rec_contact' => $_POST['rcontact'],
'Rec_emailAdd' => $_POST['remailAddress'],
'Rec_gender' => $_POST['rgender']
);
$userData2 = array(
'username' => $_POST['rusername'],
'password' => md5($_POST['rpassword']),
'userType' => "receptionist"
);
$insert = $pdo->insert($tblName,$userData);
$insert2 = $pdo->insert($tblName2,$userData2);
header("Location:../Maintenance-Receptionists.php");
这是我的dbConnect代码,它使我的receptionistAction.php能够执行crud的插入功能。
public function insert($table,$data){
if(!empty($data) && is_array($data)){
$columns = '';
$values = '';
$i = 0;
$columnString = implode(',', array_keys($data));
$valueString = ":".implode(',:', array_keys($data));
$sql = "INSERT INTO ".$table." (".$columnString.") VALUES
(".$valueString.")";
$query = $this->db->prepare($sql);
foreach($data as $key=>$val){
$query->bindValue(':'.$key, $val);
}
$insert = $query->execute();
return $insert?$this->db->lastInsertId():false;
}else{
return false;
}
}
答案 0 :(得分:0)
您需要更改条件以检查action_type
。哪会产生错误
if(isset($_REQUEST['action_type'])!empty($_REQUEST['action_type'])){
要
if(isset($_REQUEST['action_type']) && !empty($_REQUEST['action_type'])){