Validacion de campos. en una BD con PHP

Iniciado por alexkof158, 27 Noviembre 2009, 21:19 PM

0 Miembros y 1 Visitante están viendo este tema.

alexkof158

Espero me puedan ayudar llevo liando con esto varias horas
.. Me dice que el error esta aki
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\tallerphp\entradadedatos.php on line 165
<?php include_once("sesion_check.php"); ?>
<?php
session_start
();
//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','root','')or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('empresa')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function 
formRegister(){
?>

<!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>
<script type="text/‭‬javascript" src="validar.js"></script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<title>Formulario</title>
<style type="text/css">
.style1 {
background-color: #EEF7FD;
}
.style2 {
text-align: center;
}
.style3 {
color: #FFFFFF;
background-color: #0000FF;
}
</style>
<script>
function validarEntero(valor){
     //intento convertir a entero.
    //si era un entero no le afecta, si no lo era lo intenta convertir
    valor = parseInt(valor)

     //Compruebo si es un valor numérico
     if (isNaN(valor)) {
           //entonces (no es numero) devuelvo el valor cadena vacia
           return ""
     }else{
           //En caso contrario (Si era un número) devuelvo el valor
           return valor
     }
}

function valida_envia(){
//valido el nombre
cedula = document.formu.cedula.value
cedula = validarEntero(cedula)
document.formu.cedula.value=cedula
if (cedula ==""){
alert("Introduzca su Cedula, Solo Numeros.")
document.formu.cedula.focus()
return 0;
}
if (document.formu.nombre.value.length==0){
alert("Escriba Su Nombre Porfavor")
document.formu.nombre.focus()
return 0;
}
if (document.formu.apellidos.value.length==0){
alert("Introduzca sus Apellidos")
document.formu.apellidos.focus()
return 0;
}
if (document.formu.direccion.value.length==0){
alert("Introduzca su Direccion")
document.formu.direccion.focus()
return 0;
}


//el formulario se envia
document.formu.submit();

}

</script>

</head>

<body>
<h1 class="style2" style="width: 346px"><span class="style3">Datos del Cliente</span></h1>


<div id="layer1" style="position: absolute; width: 418px; height: 293px; z-index: 1; left: 8px; top: 63px; visibility: visible;" class="style1">
<form name="formu" method="post" action="entradadedatos.php" onSubmit="return valida(this);"  style="height: 37px ">
<p>Los Campos Con asteriscos(*) no son obligatorios</p>
<table style="width: 100%; height: 275px;">


<td style="width: 132px; height: 36px;">Cedula</td>
<td style="height: 36px">

<input name="cedula" style="width: 279px" type="text" ></td>
</tr>


<td style="width: 132px; height: 36px;">Nombres</td>
<td style="height: 36px">

<input name="nombre" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">Apellidos</td>
<td>
<input name="apellidos" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">Dirección</td>
<td>
<input name="direccion" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">*Ciudad</td>
<td>

<input name="ciudad" style="width: 279px" type="text" ></td>
<tr>
<td style="width: 132px">*email</td>
<td>
<input name="email" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">*Teléfono</td>
<td>

<input name="telefono" style="width: 279px" type="text" ></td>
<br>

<tr>
<td style="width: 132px">
<input type="button" value="Enviar" onclick="valida_envia()" style="width: 115px"><td colspan="2" align="center">
<input name="Reset1" style="width: 209px" type="reset" value="restablecer" ></td>



</tr>
</table>
</form>
<?php
session_start
();
// verificamos si se han enviado ya las variables necesarias.
if (isset($_POST["cedula"])) {
$cedula$_POST["cedula"];
$email $_POST["email"];

if($cedula==NULL|$email==NULL) {
echo "un campo está vacio.";
formRegister();
}else{
// Comprobamos si el nombre de usuario o la cuenta de correo ya existían
$checkuser mysql_query("SELECT cedula FROM clientes WHERE cedula='$cedula'");
$username_exist mysql_num_rows($checkuser);
$checkemail mysql_query("SELECT email FROM clientes WHERE email='$email'");
$email_exist mysql_num_rows($checkemail);
if ($email_exist>0|$username_exist>0) {
echo "la cedula  o la cuenta de correo estan ya en uso";
formRegister();
}else{
$query 'INSERT INTO clientes (cedula, nombre, email, fecha)
VALUES (\''
.$cedula.'\',\''.$nombre.'\',\''.$email.'\',\''.date("Y-m-d").'\')';
mysql_query($query) or die(mysql_error());
?>

<?php
}
}
}
}else{
formRegister();
}
?>


</div>
</body>
</html>
"noproxy"

Castg!

Primero trata de poner el codigo entre etiquetas php, asi es mas facil destingir las sentencias, pone asi [code=PHP,165][/code]



asi queda marcada la linea 165, ahora veamos:



Código (PHP,165) [Seleccionar]
<?php include_once("sesion_check.php"); ?>
<?php
session_start
();
//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','root','')or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('empresa')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function 
formRegister(){
?>

<!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>
<script type="text/‭‬‭‬javascript" src="validar.js"></script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<title>Formulario</title>
<style type="text/css">
.style1 {
background-color: #EEF7FD;
}
.style2 {
text-align: center;
}
.style3 {
color: #FFFFFF;
background-color: #0000FF;
}
</style>
<script>
function validarEntero(valor){
     //intento convertir a entero.
    //si era un entero no le afecta, si no lo era lo intenta convertir
    valor = parseInt(valor)

     //Compruebo si es un valor numérico
     if (isNaN(valor)) {
           //entonces (no es numero) devuelvo el valor cadena vacia
           return ""
     }else{
           //En caso contrario (Si era un número) devuelvo el valor
           return valor
     }
}

function valida_envia(){
//valido el nombre
cedula = document.formu.cedula.value
cedula = validarEntero(cedula)
document.formu.cedula.value=cedula
if (cedula ==""){
alert("Introduzca su Cedula, Solo Numeros.")
document.formu.cedula.focus()
return 0;
}
if (document.formu.nombre.value.length==0){
alert("Escriba Su Nombre Porfavor")
document.formu.nombre.focus()
return 0;
}
if (document.formu.apellidos.value.length==0){
alert("Introduzca sus Apellidos")
document.formu.apellidos.focus()
return 0;
}
if (document.formu.direccion.value.length==0){
alert("Introduzca su Direccion")
document.formu.direccion.focus()
return 0;
}


//el formulario se envia
document.formu.submit();

}

</script>

</head>

<body>
<h1 class="style2" style="width: 346px"><span class="style3">Datos del Cliente</span></h1>


<div id="layer1" style="position: absolute; width: 418px; height: 293px; z-index: 1; left: 8px; top: 63px; visibility: visible;" class="style1">
<form name="formu" method="post" action="entradadedatos.php" onSubmit="return valida(this);"  style="height: 37px ">
<p>Los Campos Con asteriscos(*) no son obligatorios</p>
<table style="width: 100%; height: 275px;">


<td style="width: 132px; height: 36px;">Cedula</td>
<td style="height: 36px">

<input name="cedula" style="width: 279px" type="text" ></td>
</tr>


<td style="width: 132px; height: 36px;">Nombres</td>
<td style="height: 36px">

<input name="nombre" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">Apellidos</td>
<td>
<input name="apellidos" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">Dirección</td>
<td>
<input name="direccion" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">*Ciudad</td>
<td>

<input name="ciudad" style="width: 279px" type="text" ></td>
<tr>
<td style="width: 132px">*email</td>
<td>
<input name="email" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">*Teléfono</td>
<td>

<input name="telefono" style="width: 279px" type="text" ></td>
<br>

<tr>
<td style="width: 132px">
<input type="button" value="Enviar" onclick="valida_envia()" style="width: 115px"><td colspan="2" align="center">
<input name="Reset1" style="width: 209px" type="reset" value="restablecer" ></td>



</tr>
</table>
</form>
<?php
session_start
();
// verificamos si se han enviado ya las variables necesarias.
if (isset($_POST["cedula"])) {
$cedula$_POST["cedula"];
$email $_POST["email"];

if($cedula==NULL|$email==NULL) {
echo "un campo está vacio.";
formRegister();
}else{
// Comprobamos si el nombre de usuario o la cuenta de correo ya existían
$checkuser mysql_query("SELECT cedula FROM clientes WHERE cedula='$cedula'");
$username_exist mysql_num_rows($checkuser);
$checkemail mysql_query("SELECT email FROM clientes WHERE email='$email'");
$email_exist mysql_num_rows($checkemail);
if ($email_exist>0|$username_exist>0) {
echo "la cedula  o la cuenta de correo estan ya en uso";
formRegister();
}else{
$query 'INSERT INTO clientes (cedula, nombre, email, fecha)
VALUES (\''
.$cedula.'\',\''.$nombre.'\',\''.$email.'\',\''.date("Y-m-d").'\')';
mysql_query($query) or die(mysql_error());
?>

<?php
}
}
// aca borre un "}" que me parece demas, ahora prova el codigo
}else{
formRegister();
}
?>


</div>
</body>
</html>



probalo ahora y contame como te fue ;D!

[u]nsigned

Otro error:

Código (php) [Seleccionar]
if($cedula==NULL|$email==NULL) {

Deberia ser:

Código (php) [Seleccionar]
if($cedula==NULL || $email==NULL) {

Fijate que se usan "||" (dos) como operador OR. Eso te pasa en todos los IF... :P

Saludos

No hay atajo ante la duda, el misterio se hace aquí...
Se hace carne en cada uno, el misterio es existir!

alexkof158

#3
bueno ya implemente sus respuestas y aun nada ahora el error esta en la linea
<?php include_once("sesion_check.php"); ?>
<?php
session_start
();
//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','root','')or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('empresa')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function 
formRegister(){
?>

<!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>
<script type="text/&#8237;&#8236;&#8237;&#8236;&#8237;&#8236;javascript" src="validar.js"></script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<title>Formulario</title>
<style type="text/css">
.style1 {
background-color: #EEF7FD;
}
.style2 {
text-align: center;
}
.style3 {
color: #FFFFFF;
background-color: #0000FF;
}
</style>
<script>
function validarEntero(valor){
      //intento convertir a entero.
     //si era un entero no le afecta, si no lo era lo intenta convertir
     valor = parseInt(valor)

      //Compruebo si es un valor numérico
      if (isNaN(valor)) {
            //entonces (no es numero) devuelvo el valor cadena vacia
            return ""
      }else{
            //En caso contrario (Si era un número) devuelvo el valor
            return valor
      }
}

function valida_envia(){
//valido el nombre
cedula = document.formu.cedula.value
cedula = validarEntero(cedula)
document.formu.cedula.value=cedula
if (cedula ==""){
alert("Introduzca su Cedula, Solo Numeros.")
document.formu.cedula.focus()
return 0;
}
if (document.formu.nombre.value.length==0){
alert("Escriba Su Nombre Porfavor")
document.formu.nombre.focus()
return 0;
}
if (document.formu.apellidos.value.length==0){
alert("Introduzca sus Apellidos")
document.formu.apellidos.focus()
return 0;
}
if (document.formu.direccion.value.length==0){
alert("Introduzca su Direccion")
document.formu.direccion.focus()
return 0;
}


//el formulario se envia
document.formu.submit();

}

</script>

</head>

<body>
<h1 class="style2" style="width: 346px"><span class="style3">Datos del Cliente</span></h1>


<form name="formu" method="post" action="entradadedatos.php" onSubmit="return valida(this);"  style="height: 37px; width: 420px;">
<p>Los Campos Con asteriscos(*) no son obligatorios</p>
<table style="width: 100%; height: 275px;">


<td style="width: 132px; height: 36px;">Cedula</td>
<td style="height: 36px">

<input name="cedula" style="width: 279px" type="text" ></td>
</tr>


<td style="width: 132px; height: 36px;">Nombres</td>
<td style="height: 36px">

<input name="nombre" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">Apellidos</td>
<td>
<input name="apellidos" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">Dirección</td>
<td>
<input name="direccion" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">*Ciudad</td>
<td>

<input name="ciudad" style="width: 279px" type="text" ></td>
<tr>
<td style="width: 132px">*email</td>
<td>
<input name="email" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">*Teléfono</td>
<td>

<input name="telefono" style="width: 279px" type="text" ></td>
<br>

<tr>
<td style="width: 132px">
<input type="button" value="Enviar" onclick="valida_envia()" style="width: 115px"><td colspan="2" align="center">
<input name="Reset1" style="width: 209px" type="reset" value="restablecer" ></td>



</tr>
</table>
</form>
<?php
session_start
();
// verificamos si se han enviado ya las variables necesarias.
if (isset($_POST["cedula"])) {
$cedula$_POST["cedula"];
$email $_POST["email"];
 
if($cedula==NULL||$email==NULL) {
echo "un campo está vacio.";
formRegister();
}else{
// Comprobamos si el nombre de usuario o la cuenta de correo ya existían
$checkuser mysql_query("SELECT cedula FROM clientes WHERE cedula='$cedula'");
$username_exist mysql_num_rows($checkuser);
$checkemail mysql_query("SELECT email FROM clientes WHERE email='$email'");
$email_exist mysql_num_rows($checkemail);
if ($email_exist>0||$username_exist>0) {
echo "la cedula  o la cuenta de correo estan ya en uso";
formRegister();
}else{
$query 'INSERT INTO clientes (cedula, nombre, email, fecha)
VALUES (\''
.$cedula.'\',\''.$nombre.'\',\''.$email.'\',\''.date("Y-m-d").'\')';
mysql_query($query) or die(mysql_error());
?>

<?php
}
}
// aca borre un "}" que me parece demas, ahora prova el codigo
}else{
formRegister();
}
?>



</body>
</html>
"noproxy"

[u]nsigned

#4
Los bloques parecen estar bien anidados, te sigue dando el mismo error y en la misma linea?   :rolleyes:

Otra cosa, sobre esto:
Código (php) [Seleccionar]
<?php include_once("sesion_check.php"); ?>
<?php
session_start
();


Supongo que dentro de script sesion_checker.php no usaras session_start();, asi que debrias usar session_start antes de hacer el inclde a esa funcion...y tampoco tiene mucho sentido salir y volver a entrar inmediatamente de PHP, cambia esa parte por esto:
Código (php) [Seleccionar]
<?php
session_start
();
include_once(
"sesion_check.php");


Pero respondeme lo primero, qué error te da ahora y en que linea, el mismo?

Saludos

No hay atajo ante la duda, el misterio se hace aquí...
Se hace carne en cada uno, el misterio es existir!


alexkof158

#6
gracias el error estaba que faltaba una llave al final del codigo, y en el session_check.php si tiene un session_start();
aki esta el codigo ya corregido

<?php 
include_once("sesion_check.php"); 
?>

<!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>
<script type="text/‭‬javascript" src="validar.js"></script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
<title>Formulario</title>
<style type="text/css">
.style1 {
background-color: #EEF7FD;
}
.style2 {
text-align: center;
}
.style3 {
color: #FFFFFF;
background-color: #0000FF;
}
</style>
<script>
function validarEntero(valor){
     //intento convertir a entero.
    //si era un entero no le afecta, si no lo era lo intenta convertir
    valor = parseInt(valor)

     //Compruebo si es un valor numérico
     if (isNaN(valor)) {
           //entonces (no es numero) devuelvo el valor cadena vacia
           return ""
     }else{
           //En caso contrario (Si era un número) devuelvo el valor
           return valor
     }
}

function valida_envia(){
//valido el nombre
cedula = document.formu.cedula.value
cedula = validarEntero(cedula)
document.formu.cedula.value=cedula
if (cedula ==""){
alert("Introduzca su Cedula, Solo Numeros.")
document.formu.cedula.focus()
return 0;
}
if (document.formu.nombre.value.length==0){
alert("Escriba Su Nombre Porfavor")
document.formu.nombre.focus()
return 0;
}
if (document.formu.apellidos.value.length==0){
alert("Introduzca sus Apellidos")
document.formu.apellidos.focus()
return 0;
}
if (document.formu.direccion.value.length==0){
alert("Introduzca su Direccion")
document.formu.direccion.focus()
return 0;
}


//el formulario se envia
document.formu.submit();

}

</script>

</head>

<body>

<h1 class="style2" style="width: 346px"><span class="style3">Datos del Cliente</span></h1>

<div style="position: absolute; width: 100px; height: 100px; z-index: 1" id="layer1">
<?php

//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','root','')or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('empresa')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function 
formRegister(){
?>


<form name="formu" method="post" action="entradadedatos.php" onSubmit="return valida(this);"  style="height: 37px; width: 420px;">
<p>Los Campos Con asteriscos(*) no son obligatorios</p>
<table style="width: 100%; height: 275px;">


<td style="width: 132px; height: 36px;">Cedula</td>
<td style="height: 36px">

<input name="cedula" style="width: 279px" type="text" ></td>
</tr>


<td style="width: 132px; height: 36px;">Nombres</td>
<td style="height: 36px">

<input name="nombre" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">Apellidos</td>
<td>
<input name="apellidos" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">Dirección</td>
<td>
<input name="direccion" style="width: 279px" type="text" ></td>
</tr>

<td style="width: 132px">*Ciudad</td>
<td>

<input name="ciudad" style="width: 279px" type="text" ></td>
<tr>
<td style="width: 132px">*email</td>
<td>
<input name="email" style="width: 279px" type="text" ></td>
</tr>
<td style="width: 132px">*Teléfono</td>
<td>

<input name="telefono" style="width: 279px" type="text" ></td>
<br>

<tr>
<td style="width: 132px">
<input type="button" value="Enviar" onclick="valida_envia()" style="width: 115px"><td colspan="2" align="center">
<input name="Reset1" style="width: 209px" type="reset" value="restablecer" ></td>



</tr>
</table>


</form>
<?php
session_start
();
// verificamos si se han enviado ya las variables necesarias.
if (isset($_POST["cedula"])) {
$cedula$_POST["cedula"];
$email $_POST["email"];
 
if($cedula==NULL||$email==NULL) {
echo "un campo está vacio.";
//formRegister();
}else{
// Comprobamos si el nombre de usuario o la cuenta de correo ya existían
$checkuser mysql_query("SELECT cedula FROM clientes WHERE cedula='$cedula'");
$username_exist mysql_num_rows($checkuser);
$checkemail mysql_query("SELECT email FROM clientes WHERE email='$email'");
$email_exist mysql_num_rows($checkemail);
if ($email_exist>0||$username_exist>0) {
echo "la cedula  o la cuenta de correo estan ya en uso";
formRegister();
}else{
$query 'INSERT INTO clientes (cedula, nombre, email, fecha)
VALUES (\''
.$cedula.'\',\''.$nombre.'\',\''.$email.'\',\''.date("Y-m-d").'\')';
mysql_query($query) or die(mysql_error());
?>

<?php
}
}

// aca borre un "}" que me parece demas, ahora prova el codigo
}else{
formRegister();
}
}
?>

</div>

</body>
</html>
"noproxy"