Hi,
I'm doing a registration system and as you can see when i verify the fields, if it's empty it says that the FIELD_1 misses. And what i want is if the field is empty says that and then goes back, but i don't wanto the info already written disappears.
registration
<?PHP
include 'topo.php';
?>
<!-- content -->
<div class="indent">
<h2> Inscrição </h2>
<form action="envia.php" method="post" onsubmit="return validar()" >
<fieldset>
<legend> ALUNO </legend>
<br/>
<div class="field"><label>Username*: </label><input type="text" size="30" name = "username"/></div>
<br/>
<div class="field"><label>Password*: </label><input type="password" size="25" name = "pass"/></div>
<br/>
<div class="field"><label>Confirma Password*: </label><input type="password" size="25" name = "conf_pass"/></div>
<br/>
<div class="field"><label>Nome*: </label><input type="text" size="40" name = "nome"/></div>
<br/>
<div class="field"><label>Data de Nascimento*: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="3" maxlength="2" name = "dia"/> / <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="3" maxlength="2" name = "mes"/> / <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="5" maxlength="4" name = "ano"/> (DD/MM/AAAA)</div>
<br/>
<div class="field"><label>Morada: </label><input type="text" onkeypress="return onlyNumbers();" size="39" name = "morada"/></div>
<br/>
<div class="field"><label>Código Postal: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="5" maxlength="4" name = "cp1"/> - <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="4" maxlength="3" name = "cp2"/></div>
<br/>
<div class="field"><label>Telemóvel*: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="10" maxlength="9" name = "tele"/></div>
<br/>
Curso*: <select name="curso">
<option value = 1> Piano </option>
<option value = 2> Orgão </option>
<option value = 3> Guitarra Elétrica </option>
<option value = 4> Guitarra Acústica </option>
<option value = 5 Violino </option>
<option value = 6> Canto </option>
<option value = 7> Bateria </option>
<option value = 8> Saxofone </option>
<option value = 9> Flauta </option>
<option value = 10> Baixo </option>
<option value = 11> Violoncelo </option>
</select>
<br/>
<br/>
<div class="field"><label>E-Mail*: </label><input type="text" value="" name = "email" size = "25"/></div>
<br/>
Observações:
<br/>
<textarea cols="30" rows="7" name="obs"></textarea>
</fieldset>
<br/>
<fieldset>
<legend> ENCARREGADO DE EDUCAÇÃO </legend>
<br/>
<div class="field"><label>Nome*: </label><input type="text" size="40" name = "nome_ee"/></div>
<br/>
<div class="field"><label>Morada: </label><input type="text" size="39" name = "morada_ee"/></div>
<br/>
<div class="field"><label>Código Postal: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="5" maxlength="4" name = "cp1_ee"/> - <input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="4" maxlength="3" name = "cp2_ee"/></div>
<br/>
<div class="field">Telemóvel*: </label><input id="txtChar" onkeypress="return isNumberKey(event)" type="text" size="10" maxlength="9" name = "tele_ee"/></div>
<br/>
<div class="field"><label>E-Mail*: </label><input type="text" value="" name = "email_ee" size = "25"/></div>
</fieldset>
<br/>
* Campos Obrigatórios
<br/>
<input type="submit" value="Enviar">
<input type="Reset" value="Apagar">
</form>
</div>
</div>
<?PHP
include 'rodape.php';
?>
send
<?PHP
//ligar base de dados
include "db_connect.php";
/////////// ALUNO ///////////////
$username = $_POST ['username'];
$pass = $_POST ['pass'];
$conf_pass = $_POST ['conf_pass'];
$nome = $_POST ['nome'];
$dia = $_POST ['dia'];
$mes = $_POST ['mes'];
$ano = $_POST ['ano'];
$data_nascimento = $dia .'-'. $mes .'-'. $ano;
$morada = $_POST ['morada'];
$cp1 = $_POST ['cp1'];
$cp2 = $_POST ['cp2'];
$cp_aluno = $cp1 .'-'. $cp2;
$curso = $_POST ['curso'];
$telemovel = $_POST ['tele'];
$email = $_POST ['email'];
$observacao = $_POST ['obs'];
///////////ENC.EDU.///////////////
$nome_ee = $_POST ['nome_ee'];
$morada_ee = $_POST ['morada_ee'];
$cp1_ee = $_POST ['cp1_ee'];
$cp2_ee = $_POST ['cp2_ee'];
$cp_ee = $cp1_ee .'-'. $cp2_ee;
$tele_ee = $_POST ['tele_ee'];
$email_ee = $_POST ['email_ee'];
include 'veref_aluno.php';
include 'veref_ee.php';
//inserir na base de dados
$sql = "INSERT INTO alunos (username, password, nome_aluno, data_nascimento, morada_aluno, cp_aluno, telemovel_aluno, email_aluno, observacoes, nome_ee, morada_ee, cp_ee, telemovel_ee, email_ee)
VALUES('". $username. "', '" . $pass ."','" . $nome ."', '". $data_nascimento ."', '". $morada ."', '". $cp_aluno ."', '". $telemovel ."', '". $email ."','" . $observacao . "','". $nome_ee ."', '". $morada_ee ."', '". $cp_ee ."', '". $tele_ee ."', '". $email_ee ."')";
if(mysql_query($sql))
{
echo "Inscrição feita com sucesso. Em breve receberá um email para confirmar os dados. Obrigado!";
//header ('Location: index.php');
}
?>
veref_reg student
<?PHP
$back = $_SERVER['HTTP_REFERER'];
// verifica username
if (empty($username))
{
die("<script>alert(\"Preencha o Username.\");
location.href='". $back ."';
</script>");
}
// verifica password
if (empty($pass))
{
die("Preencha a 'Password'.");
}
//verifica conf_pass
// verifica nome
if (empty($nome))
{
die("Preencha o 'Nome'.");
}
//verifica telemovel
if (empty($telemovel))
{
die("Preencha o 'Telemovel'.");
}
// verifica email
if (empty($email))
{
die("Preencha 'Email'.");
}
?>
Do you understand?
If you do, can you help me?
Thank you,
PF2G