Jump to content

Recommended Posts

Posted (edited)

Boas a todos,

tenho seguinte codigo php para já para inserir numa BD mysql.

<?php


include("../loginBD.php");

$idProposta = $_GET['idProposta'];


$insere1 = mysql_query("INSERT INTO candidatura (Proposta_idProposta, EstadoCand_idEstadoCand) VALUES ('".$idProposta."', '5')");

if ($insere1 == true){
$insere2  mysql_query("INSERT INTO candidato (Aluno_idAluno, Candidatura_idCandidatura) VALUES ('".$_SESSION['utilizadorID']."', '""')");
}

?>

Existe alguma maneira de na primeira inserção do código acima ir buscar o idCandidatura da tabela onde foi inserido logo o valor.

Esse idCandidatura é auto_increment.

Alguém me pode dizer?

Edited by brunoais
adicionado geshi
Posted
$insere1 = mysql_query("INSERT INTO candidatura (Proposta_idProposta, EstadoCand_idEstadoCand) VALUES ('{$idProposta}', '5')");
$idCandidatura = mysql_insert_id(); // <-------------

if ($insere1 == true){
$insere2 = mysql_query("INSERT INTO candidato (Aluno_idAluno, Candidatura_idCandidatura) VALUES ('{$_SESSION['utilizadorID']}', '{$idCandidatura}')");
}
IRC : sim, é algo que ainda existe >> #p@p

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.