JoaoNascimento Posted May 20, 2012 at 12:16 AM Report #456922 Posted May 20, 2012 at 12:16 AM (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 May 20, 2012 at 01:24 PM by brunoais adicionado geshi http://www.joaonascimento.info
pedrosorio Posted May 20, 2012 at 12:53 AM Report #456923 Posted May 20, 2012 at 12:53 AM Podes usar esta função do MySQL: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id Não respondo a dúvidas por mensagem.
HappyHippyHippo Posted May 20, 2012 at 08:57 AM Report #456926 Posted May 20, 2012 at 08:57 AM $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 Portugol Plus
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now