Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde.
Gostaria de saber se alguém poderia me orientar de como fazer para o sistema verificar a idade da pessoa que está se cadastrando ao colocar a data de nascimento.
Página cadastro.php
<?php
include_once ("includes/config.php");
include_once ("../../config_set.php");
abreConexao();
$re = mysql_query("SELECT * FROM estados ORDER BY estado") or die("Consulta inválida: " . mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo _SITE_ ?></title>
<link rel="stylesheet" href="index.css" type="text/css" />
<link rel="shortcut icon" href="../<?php echo _SHORTCUT_ICON_ ?>" type="image/x-icon" />
<script type="text/javascript">
<!--
function mascara_telefone() {
if(document.cadUsuario.telefone.value.length == 2) {
document.cadUsuario.telefone.value += ' ';
}
if(document.cadUsuario.telefone.value.length == 7) {
document.cadUsuario.telefone.value += '-';
}
}
function mascara_celular() {
if(document.cadUsuario.celular.value.length == 2) {
document.cadUsuario.celular.value += ' ';
}
if(document.cadUsuario.celular.value.length == 7) {
document.cadUsuario.celular.value += '-';
}
}
function somenteNumeros(event) {
var kCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
var caract = new RegExp(/^[0-9]+$/i);
var caract = caract.test(String.fromCharCode(kCode));
if(!caract){
return false;
}
}
function verify_form(obj_form) {
if (obj_form.nome.value == "") {
alert("É necessário preencher o campo 'Nome'.");
obj_form.nome.focus();
}else if(obj_form.email.value == ""){
alert("É necessário preencher o campo 'E-mail'.");
}else if(obj_form.estado.value == "-"){
alert("Por favor, escolha um estado.");
}else if(obj_form.cidade.value == ""){
alert("É necessário preencher o campo 'Cidade'.");
return false;
history.back(1);
} else {
return true;
}
}
//-->
</script>
</head>
<body background="fundo_site2.png">
<div class="fundo_centro">
<div class="logo2"><img src="logo_small.png" /></div>
<form method="post" action="cadastrar.php" name="cadUsuario" onsubmit="return verify_form(this);">
<table cellspacing="0" cellpadding="1" border="0" width="400px;">
<tr>
<td>Nome Completo:</td>
<td><input name="nome" type="text" class="textBox" id="nome" maxlength="200" /></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" id="email" maxlength="150" class="textBox" /></td>
</tr>
<tr>
<td>Data de Nascimento:</td>
<td>
<?php
echo monta_select("dia", 1, 31);
echo monta_select("mes", 1, 12);
echo monta_select("ano", 1940, 1993);
?>
</td>
</tr>
<tr>
<td>Sexo:</td>
<td><input type="radio" name="sexo" value="Masculino" checked="checked" /><label>Masculino</label>
<input type="radio" name="sexo" value="Feminino" /><label>Feminino</label></td>
</tr>
<tr>
<td>Estado:</td>
<td><select name="estados" id="estados" class="textBox">
<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
while($l = mysql_fetch_array($re)) {
$id = $l["idestado"];
$estado = $l["estado"];
$uf = $l["uf"];
echo "<option value=\"$id\">$uf - $estado</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Cidade:</td>
<td><input name="cidade" type="text" id="cidade" maxlength="64" class="textBox" /></td>
</tr>
<tr>
<td>Telefone fixo:</td>
<td><input type="text" name="telefone" id="telefone" onkeypress="return somenteNumeros(event);" onkeyup="mascara_telefone()" maxlength="12" /></td>
</tr>
<tr>
<td>Celular:</td>
<td><input type="text" name="celular" id="celular" onkeypress="return somenteNumeros(event);" onkeyup="mascara_celular()" maxlength="12" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="submit" value="Cadastrar" class="botao_cadastrar" /></td>
</tr>
</table>
</form>
</div>
<?php
abreConexao();
include_once('layout/footer.php');
?>
</div>
</body>
</html>
Página cadastrar.php
<?php
header("Content-Type: text/html; charset=ISO-8859-1", true);
if($_SERVER["REQUEST_METHOD"] == "POST") {
$nome = $_POST["nome"];
$email = $_POST["email"];
$nascimento = "{$_POST["ano"]}-{$_POST["mes"]}-{$_POST["dia"]}";
$sexo = $_POST["sexo"];
$estado = $_POST["estado"];
$cidade = $_POST["cidade"];
$telefone = $_POST["telefone"];
$celular = $_POST["celular"];
require_once "includes/config.php";
abreConexao();
mysql_query("INSERT INTO usuario VALUES ( '', '$nome', '$email', '$nascimento', '$sexo', '$estado', '$cidade', '$telefone', '$celular')");
if(mysql_affected_rows() == 1){
echo "<script>alert('Seu cadastro foi efetuado com sucesso.');location.href='index.php';</script>";
} else {
echo "<script>alert('Seu e-mail já está cadastrado em nosso sistema.'); history.back(1);</script>";
exit;
}
}
@mysql_close();
?>
Se alguém puder me ajudar.
Obrigado pessoal.
Carregando comentários...