pdo - How to insert data into nested tables through PHP? -


i think related pdo.

this patientinfo table

patientid | name | age | email | address 

and remarks tables

patientid | remarksid | date | description 

i'd insert data patientinfo , remarks table patientid of both tables synchronized.

problem dont know how query this. gives me error.

$query = "insert patientinfo (name, age, email, address)               values (:name, :age, :email, :address);";      $query_params = array(             ':name'     => $_post['name'],             ':age'      => $_post['age'],             ':email'    => $_post['email'],             ':address'  => $_post['address'],     );      $query = "insert remarks (patient_id, description) values (:patient_id, :remarks) remarks.patient_id = patientinfo.patient_id;";     $query_params = array(':remarks' => $_post['remarks']);      try{         $stmt = $dbname->prepare($query);         $result = $stmt->execute($query_params);     }      catch(pdoexception $ex){             $response["success"] = 0;             $response["message"] = $ex ;              die(json_encode($response));     } 

i made patientid in patientinfo autoincrement. please! thank help!

$query = "insert patientinfo (name, age, email, address)               values (:name, :age, :email, :address);";  $query_params = array(         ':name'     => $_post['name'],         ':age'      => $_post['age'],         ':email'    => $_post['email'],         ':address'  => $_post['address'], );  try{     $stmt = $dbname->prepare($query);     $stmt->execute($query_params);      $patient_id = $dbname->lastinsertid();      $query = "insert remarks (patientid, description) values (:patient_id, :remarks)";     $query_params = array(':remarks' => $_post['remarks'],':patient_id'=>$patient_id);      $q = $dbname->prepare($query);      $q->execute($query_params);  }catch(pdoexception $ex){         $response["success"] = 0;         $response["message"] = $ex ;          die(json_encode($response)); } 

you should write that. check column names please(patientid or patient_id ? )


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -