0
I have a page for user registration and Internet in a single page, I need to delete the data after clicking register and insert in the bank, because if I update the page the record is duplicated in the bank, any idea?
<?php
if (isset($_GET['cadastra']) && $_GET['cadastra'] == 'add') {
$cadastra = mysql_query("INSERT INTO cliente (ordemservico, nome, data,fone, produto, status, descricao) VALUES ('$ordemservico', '$_GET[nome]', '$_GET[data]', '$_GET[fone]', '$_GET[produto]', '$_GET[status]', '$_GET[descricao]')");
if($cadastra == '1') {
echo "Cadastrado com sucesso ! OS Número: $ordemservico <br /> <a href=\"admin.php\">Atualizar<a/>";
}else{
echo "Erro ao cadastrar !";
}
}
?>
Form
<form id="form1" name"form1" method"post" action"" enctype="multipart/form-data">
<div align="center">
<table border="0" align="center">
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Nome:</td>
<td><span id="sprytextfield1">
<label>
<input name="nome" type="text" id="nome" size="43" />
</label>
<span class="textfieldRequiredMsg"><font face="Arial, Helvetica, sans-serif" size="1" color="#FF0000" >Informe seu nome</font></span></span></td>
</tr>
<td>Fone:</td>
<td><label>
<input name="fone" type="text" id="fone" size="43" />
<br />
</label></td>
</tr>
<td>Produto:</td>
<td><span id="sprytextfield2">
<label>
<input name="produto" type="text" id="produto" size="43" />
</label>
<span class="textfieldRequiredMsg"><font face="Arial, Helvetica, sans-serif" size="1" color="#FF0000" >Informe o produto</font></span></span></td>
</tr>
<td>Status:</td>
<td><label>
<label for="status"></label>
<select name="status" id="status" >
<option value="-1" selected="selected">Selecione</option>
<option>Aguardando</option>
<option>Em Atendimento</option>
<option>Finalizado</option>
</select>
<br />
</label></td>
</tr>
<tr>
<td>Descrição:</td>
<td><label>
<textarea name="descricao" cols="46" rows="5" id="descricao"> </textarea>
</label></td>
</tr>
<tr>
<td><label for="data"></label>
<input type="hidden" name="data" id="data" value="<?php echo date('Y-m-d')?>" /></td>
<td align="right"><label>
<input type="hidden" name="cadastra" value="add" />
<input type="submit" name="add" id="add" value=" Cadastrar " />
</label></td>
</tr>
</table>
</form>
Make a http redirect right after registering in DB instead of displaying content. You can redirect to the same page, which also works.
– Bacco
@Bacco in my code now I’m doing a refresh of 2 seconds "<meta HTTP-EQUIV='refresh' CONTENT='2;URL=clients.php'>" but it doesn’t seem like a good idea, you know tell me how to make this redirect?
– Rafael Assmann
You can delete the form data after the Insert, and when it is updated with F5, your message will be displayed stating to fill in the fields.
– Papa Charlie
@Bacco the code is as you described but when registering I get the error: "Warning: Cannot Modify header information - headers already sent by (output Started at C: xampp htdocs folder admin cadastro_clientes.php:196) in C: xampp htdocs folder admin cadastro_clientes.php on line 220"
– Rafael Assmann
@Rafaelassmann this part is easy, and it is a sign that you are on the right track. Now just take out all the things that send information on the PHP screen before giving the redirect. See more here: http://answall.com/questions/4251/
– Bacco
Understood, I got it here! Thank you so much for the support, 10! @Bacco
– Rafael Assmann