Olá! Eu preciso de ajuda no meu código, preciso inserir informações em 3 tabelas diferentes mas dá erro e só insere em uma, sendo ela ingredientes. Não sei mais oque fazer e preciso disso urgente.
a tabela receita tem: id, nome, descricao, cliente_id.
a de ingrediente: id, nome.
e a ingrediente_has_receita: quantidade, ingrediente_id, receita_id.
Esse é o codigo:
<?php
$nome = $_POST['nome'];
$descricao = $_POST['descricao'];
$ingrediente = $_POST['ingredientes'];
$quantidade = $_POST['quantidade'];
$con = new PDO("mysql:host=localhost; dbname=eathat", "root", "");
$sql = $con->prepare("INSERT INTO receita VALUES (NULL, '$nome', '$descricao', NULL);");
$sql2 = $con->prepare("INSERT INTO ingrediente VALUES (NULL, '$ingrediente');");
$sql3 = $con->prepare("INSERT INTO ingrediente_has_receita VALUES ('$quantidade', NULL, NULL);");
$sql->execute();
$sql2->execute();
$sql3->execute();
$row = $sql->fetchObject();
$row = $sql2->fetchObject();
$row = $sql3->fetchObject();
if ($row) {
echo"<script language='javascript' type='text/javascript'>alert('Receita cadastrada com sucesso!');window.location.href='cadastrarprato.php'</script>";
header("casdastrarprato.php");
} else {
echo"<script language='javascript' type='text/javascript'>alert('Receita cadastrada com sucesso!');window.location.href='cadastrarprato.php'</script>";
}
?>