0
I need to make a CRUD system with html and PHP, in which PHP takes a certain measure according to the type of request (whether it is register, update or delete) but I don’t know how to pass this from html to PHP.
HTML:
<form action="index.php" method="POST">
<div class="form-group">
<input type="nome" name="nome" class="form-control" placeholder="Nome: ">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email: ">
</div>
<div class="form-group">
<input type="date" name="nascimento" class="form-control" placeholder="Data de nascimento: ">
</div>
<div class="form-group">
<input type="password" name="senha" class="form-control" placeholder="Senha:">
</div>
<button type="submit" name='cadastro' class="btn btn-primary">Cadastrar</button>
</form>
PHP:
<?php
// 'cadastro' refere-se ao name do submit, mas nao funcionou
if($_POST['cadastro']) {
$banco = mysqli_connect('127.0.0.1', 'root', '', 'crud');
$nome = $_POST['nome'];
$email = $_POST['email'];
$senha = $_POST['senha'];
$nascimento = $_POST['nascimento'];
$sql = "INSERT INTO usuario VALUES ('', '$nome' , '$email' , '$senha', '$nascimento')";
echo "Cliente cadastrado com sucesso!";
mysqli_query($banco, $sql);
mysqli_close($banco);
echo "Cliente cadastrado com sucesso!";
}
?>
eu preciso saber reconhecer oq o usuario quer, se é inserir algo, remover algo ou alterar algo
... You forgot the most important thing, which is the user trying to find flaws. There will always be someone to change the 'attr name' of your button to edit/delete something that does not exist or does not belong to it.– Papa Charlie