Close the connection before inserting!?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Consolas
Forum Newbie
Posts: 13
Joined: Wed Apr 09, 2008 7:07 pm

Close the connection before inserting!?

Post by Consolas »

Hello everyone

I'm going completely nuts.

$id_revista_escolhida = $_POST['id_revista_escolhida'];

$conexao = $mysqli->prepare(" SELECT titulo,descricao,banner,imagem1,imagem2,bannervertical,gradiente,posicao FROM menus WHERE idrevista = ? ORDER BY id ASC");
$conexao_inserir = $mysqli->prepare("INSERT INTO menus (titulo,descricao,banner,imagem1,imagem2,idrevista,bannervertical,gradiente,
posicao) VALUES (?,?,?,?,?,?,?,?,?)");
$conexao_inserir->bind_param('sssssissi', $titulo, $descricao, $banner, $imagem1, $imagem2, $_SESSION['idrevista'], $bannervertical, $gradiente, $posicao);

$conexao->bind_param('i',$id_revista_escolhida);
$conexao->execute();
$conexao->bind_result($titulo, $descricao, $banner, $imagem1, $imagem2, $bannervertical, $gradiente, $posicao);

$conexao->fetch();
$conexao->close();

$conexao_inserir->execute();


//$conexao->close();
$mysqli->close();


Regarding the bold section, if i dont close the $conexao connection, the insert doesnt output an error but doesnt insert any data. If i close it, it works. My main issue is i need to do a cylce ( while ( $conexao->fetch() )...etc etc ) so i really need to understand why this is happening.

Thank you very much for all your help!!
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Close the connection before inserting!?

Post by ghurtado »

How could you execute the insert after closing the connection and it still work?
Consolas
Forum Newbie
Posts: 13
Joined: Wed Apr 09, 2008 7:07 pm

Re: Close the connection before inserting!?

Post by Consolas »

Hello

I didnt make myself clear. I'm not closing the connection, im closing the SELECT prepare statemente.
Post Reply