I have two tables ( cliente
and telefone
), I need to insert the name in the cliente
table and the client phone in the telefone
table, at the same time, by the same form.
In the HTML form I was able to put all the fields (name, ddd, phone) but I can not send them to both tables.
if(isset($_POST['nome'])){
$nome = filter_input(INPUT_POST,'nome',FILTER_SANITIZE_STRING);
$ddd = filter_input(INPUT_POST,'ddd',FILTER_SANITIZE_STRING);
$telefone = filter_input(INPUT_POST,'telefone',FILTER_SANITIZE_STRING);
$solicita = "INSERT INTO 'cliente' ('nome') VALUES ($nome),
INSERT INTO 'telefone' ('ddd','telefone') VALUES ($ddd,$telefone)";
$query = mysqli_query($conn,$solicita);
if($linha_usuario = mysqli_insert_id($conn)){
echo "Cadastrado com sucesso";
}else{
echo "Erro ao cadastrar";
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Desafio Estágio</title>
<link rel="stylesheet" href="estilo.css">
</head>
<body>
<h1>Cadastro de clientes</h1>
<form action="index.php" method="post" id="form">
<label for="nome">Nome</label>
<input type="text" id="nome" name="nome">
<label for="ddd">D.D.D</label>
<input type="text" id="ddd" name="ddd" size="2">
<label for="telefone">Telefone</label>
<input type="text" id="telefone" name="telefone">
<input type="submit" value="Cadastrar" id="cadastrar">
</form>
</body>
</html>