Inserting data in PHP

1

Good morning! I need a help Person I am facing the following problem

  • I have two tables in the (clinics) and (users)

  • I want to insert the data in the two tables in a way that is user- that the form is sent, the form data I've already made I'm pulling the form all the data is already being fetched.

  • The problem is that I need to insert the fields of the same form into
    individual tables

  • in the (clinics) table I only have one field called clinic_name where, this should be the first field to be filled at the time of submission
    of the form because this table (clinics) will generate an id that I have to pick up the (users) table in the sequence

  • Where to populate the (users) table consequently I will have to search the (clinics) table and get the id of the clinic and fill in the user_clincis_id field in the table (users)

  • The two tables are (clinics) and (users) key relationship between them where (clinics 1) (users N) one for
    many associative

  • Well I've done a lot already, I've even thought about doing a routine random

    
asked by anonymous 12.07.2016 / 15:11

2 answers

2

Hi, how are you? Since it is a PHPOO I can give this example. In SQL you can not do in a query the insert into two different tables I suggest at the end of the method of saving the clinic using a

 return $variavelConexaoBD->lastInsertId();

Already in your so-called save method

$id_clinica = $EntidadeClinica->salvar_clinica($objClinica); 

After saving the clinic it will return the ID by PHP's lastInsertId () method

$EntidadeUsers->salvar_usuarios($objClinica, $id_clinica);
    
12.07.2016 / 15:31
0

It seems that you are using codeigniter, so to get the inserted id you can use

$this->db->insert_id

In this way you can add in the clinics table and then get the inserted id to add in users.

Font

    
05.08.2016 / 04:40