0
I need to create a form that creates, deletes, and edits a record in my database. My question is: How to make it perform an action by clicking the button?
If I click on any button it only performs the save action.
The buttons need to be with the icons, and not just written 'Save'.
Follows the codes:
cadastroCliente.html
<html>
<head>
<meta charset="utf-8">
<title>Cadastrar cliente - World Bikes</title>
<link href="css/ordemstyle.css" rel="stylesheet" type="text/css">
<link href="css/fundo.css" rel="stylesheet" type="text/css">
</head>
<body id="fundo">
<img src="css/img/logo.png" alt="World Bikes" width="20%">
<nav id="menu">
<ul>
<li><a href="agenda.html">Agenda</a></li>
<li><a href="cadastro.html">Cadastro</a></li>
<li><a href="ordemServico.html">Ordem de Serviço</a></li>
<li><a class="active" href="cadastroCliente.html">Cadastrar Cliente</a></li>
</ul>
</nav>
<hr style="background-color: #33c208">
<h1 id="titulo">Cadastro de Cliente</h1>
<div id=form2>
<form method="post" action="salvarCliente.php">
<fieldset id=borda>
<label for="cpf">CPF: </label>
<br />
<input type="text" name="cpf" id="cpf" class="campo1" />
<div class="button">
<input src="icons/buscar.png" type="image">
</div>
<br />
<label for="name">Nome do cliente:</label>
<br />
<input type="text" name="nome" id="nome" />
<br />
<label for="telefone">Telefone:</label>
<br />
<input type="text" name="telefone" id="telefone" />
<br />
<label for="modelo">Modelo da bicicleta:</label>
<br />
<input type="text" name="modelo" id="modelo" />
<br />
<label for="aro">Aro da bicicleta: </label>
<br />
<input type="text" name="aro" id="aro" />
<br />
<label for="cor">Cor da bicicleta:</label>
<br />
<input type="text" name="cor" id="cor" />
<br />
<div class="button">
<input type="image" name="salvar" src="icons/Salvar2.png">
<input type="image" name="excluir src="icons/excluir4.png">
<input type="image" name="salvar" src="icons/Editar4.png">
</div>
</fieldset>
</form>
</div>
</body>
</html>
salvarCliente.php
<?php
//conectar no banco de dados - incluir o arquivo do banco
if($_POST){
include "conecta.php";
//pega as variaveis vindas do formulario
$nome = ($_POST["nome"]);
$cpf = trim($_POST["cpf"]);
$telefone = trim($_POST["telefone"]);
$modelo = trim($_POST["modelo"]);
$aro = trim($_POST["aro"]);
$cor = trim($_POST["cor"]);
// para validar os campos em branco.
if (empty($nome)) {
//se o login estiver em branco exibe esta mensagem: "preencha o login"
echo "<script>alert('Preencha o nome');history.back();</script>";
}
if (empty($cpf)) {
echo "<script>alert('Preencha o campo CPF');history.back();</script>";
}
if (empty($telefone)) {
echo "<script>alert('Preencha o campo telefone');history.back( </script>";
}
if (empty($modelo)) {
echo "<script>alert('Preencha o campo modelo');history.back();</script>";
}
if (empty($aro)) {
echo "<script>alert('Preencha o campo aro');history.back();</script>";
}
if (empty($cor)) {
echo "<script>alert('Preencha o campo cor');history.back();</script>";
}
else {
$sql = "INSERT INTO cliente (nome, cpf, telefone, modelo, aro, cor)
VALUES ('$nome', '$cpf', '$telefone', '$modelo','$aro','$cor')";
mysqli_select_db($_SG['link'],"oficina") or die ("Banco de Dados Inexistente!");
//inserindo dados no banco
mysqli_query($_SG['link'], $sql)
or die ("<script>alert('Erro na gravação');history.back();</script>");
echo "<script>alert('Cliente cadastrado');window.location.href='ordemServico.html';</script>";
}
}
?>
https://i.stack.Imgur.com/evLUR.png see why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252
I put an example with the statements, Insert, delete and upadate, including a functional example that will be active for a certain time.
– user60252