Hello,
How do I get the id that is autoincrement without the item being registered in the database? Or I will have to do 2 process, first register the post, then register the post in the category?
I'm with a system to register posts here, and the tables are separate so I can register the same post in several categories:
Table:Products
Table:Categories
Relationshiptable:Products~Categories
PHPcodetoregisterthepost:
$cadastrarItem=$conexao->prepare("INSERT INTO tb_mark (name_mark, description_mark, keywords, att_mark, image_mark, link) VALUES (:title, :description, :keywords, NOW(), :img, :linkitem)");
$cadastrarItem->bindParam(':title', $title, PDO::PARAM_STR);
$cadastrarItem->bindParam(':img', $novoNome, PDO::PARAM_STR);
$cadastrarItem->bindParam(':description', $description, PDO::PARAM_STR);
$cadastrarItem->bindParam(':keywords', $tags, PDO::PARAM_STR);
$cadastrarItem->bindParam(':linkitem', $linkitem, PDO::PARAM_STR);
$verificaItens = $conexao->prepare("SELECT name_mark FROM tb_mark WHERE name_mark=:title");
$verificaItens->bindParam(':title', $title, PDO::PARAM_STR);
$verificaItens->execute();
if($verificaItens->rowCount() == 0)
{
$cadastrarItem->execute();
echo '<script language= "javascript">
location.href="/admin_include_brand/register_item";
</script>';
}
else
{
echo '<script language= "javascript">
location.href="/admin_include_brand/register_error";
</script>';
}
And it would be basically this for me to register the category in the table:
$cadastrarItemCategoria = $conexao->prepare("INSERT INTO tb_category_itens (id_item, id_category) VALUES (:id_item, :id_category)");
// id_item = 'id' da tabela produtos
// id_category = 'id' da tabela categorias
$cadastrarItemCategoria->bindParam(':id_item', $id_item, PDO::PARAM_STR);
$cadastrarItemCategoria->bindParam(':id_category', $category, PDO::PARAM_STR);