I'm doing a registration system in php, and using mysql as db, I've already been able to do the registration page and it's working normally. The problem is that now I need a link to be created when the database is created and clicking on it to edit the data in the database.
The code that performs the registration:
<?php
/**
* Created by PhpStorm.
* User: Arnaud
* Date: 22/05/2017
* Time: 16:38
*/
$nome = $_POST["txtnome"];
$email = $_POST["txtemail"];
$telefone = $_POST["txttelefone"];
$senha = $_POST["txtpass"];
$data = $_POST["txtdata"];
$id = $_POST["id"];
$con = mysqli_connect("localhost", "root", "");
mysqli_select_db($con,"testeconstrusite");
if (mysqli_connect_errno())
{
echo "Falha ao conectar ao servidor MySQL: " . mysqli_connect_error();
}
if(!empty($nome) && !empty($email) && !empty($telefone) && !empty($senha) && !empty($data) && !empty($id) && empty($id)) {
mysqli_query($con, "insert into clientes (nome_cliente, email_cliente, telefone_cliente, senha_cliente, data_nasc_cliente) VALUE('$nome', '$email', '$telefone', '$senha', STR_TO_DATE('$data','%d/%m/%Y'))");
$id_inserido = mysqli_insert_id($con);
echo "Cliente inserido com id de número: $id_inserido <br>";
echo "Para editar o usuário cadastrado clique <a href='index.php?id=$id_inserido'>aqui</a>";
}
elseif(!empty($nome) && !empty($email) && !empty($telefone) && !empty($senha) && !empty($data) && !empty($id) && !empty($id)){
mysqli_query($con, "update clientes set nome_cliente ='$nome', email_cliente='$email', telefone_cliente='$telefone', senha_cliente='$senha', data_nasc_cliente=STR_TO_DATE('$data','%d/%m/%Y') where id_cliente = '$id'");
}
else{
echo "Preencha todos os campos!";
}
The form page:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" media="all" href="estilos/estilo.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.min.js"></script>
<title>Cadastro</title>
</head>
<body>
<div id="formulario" class = formulario>
<form action="cadastrar.php" method="post">
<input type='text' name="id" class='campo' id="id" value="<?php if(!empty($_GET["id"])){echo $_GET["id"];}; ?>">
<label>Nome *</label><br>
<input type='text' name="txtnome" class='campo' id="txtnome" required>
<br>
<label>E-mail *</label><br>
<input type="email" class='campo' required="required" name="txtemail" id="txtemail" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$">
<br>
<label>Telefone *<span class="esmaecido"></span> </label><br>
<script type="text/javascript">$("#txttelefone").mask("(00) 0000-00009");</script>
<input type="tel" class="campo" name="txttelefone" id="txttelefone" required="required" pattern="\([0-9]{2}\)[\s][0-9]{4}-[0-9]{4,5}" />
<br>
<label>Senha *</label><br>
<input type="password" name="txtpass" class='campo' required="required" id="txtpass">
<br>
<label>Data de Nascimento *</label><br>
<script type="text/javascript">$("#txtdata").mask('00/00/0000');</script>
<input type='data' name="txtdata" id="txtdata" class='campo' required="required">
<br>
<input type='submit' name='BTEnvia' value='Cadastrar' class = botao><br>
</form>
</div>
</body>