So, I have two tables ativos
and colaboradores
and they are linked by id_colaborador (FK)
on my update page, I'm able to change the id_colaborador
but instead of changing the ID
I want to write the name
that match to that ID
but I think I need multiple WHERE
conditions and SELECT
, may anyone help me out? Thanks!
I have the following code to update
$sql = "UPDATE ativos SET ativo = ?, comentario = ?, data_aquisicao = ?, localizacao = ?, fabricante = ?, modelo = ?, imei = ?,
numero_serie = ?, ativo_sap = ?, anexo_a = ?, evento = ?, data_evento = ?, SELECT id_colaborador FROM colaboradores WHERE nome = ? AND WHERE id_ativo = ?";
UPDATE
I've already try to separete the two statements like this:
$sql = "UPDATE ativos SET ativo = ?, comentario = ?, data_aquisicao = ?, localizacao = ?, fabricante = ?, modelo = ?, imei = ?,
numero_serie = ?, ativo_sap = ?, anexo_a = ?, evento = ?, data_evento = ?, id_colaborador = ? WHERE id_ativo = ?";
$sql2 = "SELECT id_colaborador FROM colaboradores WHERE nome = ?";
$q = $pdo->prepare($sql,$sql2);
But it gives me the following error:
Warning: PDO::prepare() expects parameter 2 to be array, string given in C:\xampp\htdocs\gestao\Colaboradores\ativo_update.php on line 120
Fatal error: Uncaught Error: Call to a member function execute() on boolean in C:\xampp\htdocs\gestao\Colaboradores\ativo_update.php:121 Stack trace: #0 {main} thrown in C:\xampp\htdocs\gestao\Colaboradores\ativo_update.php on line 121