Foros del Web » Programando para Internet » PHP »

Problema al validar formulario.

Estas en el tema de Problema al validar formulario. en el foro de PHP en Foros del Web. Hola a toda esta gran comunidad, saludos cordiales de ante mano. Tengo unas dudas y problemas al validar mi formulario.. Tengo varios campos para validar, ...
  #1 (permalink)  
Antiguo 02/07/2009, 12:08
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Problema al validar formulario.

Hola a toda esta gran comunidad, saludos cordiales de ante mano.

Tengo unas dudas y problemas al validar mi formulario..

Tengo varios campos para validar, ejemplo un campo llamdao txt_numcelular.
En el cual se ingresa el numero de celular.


Mi duda es como validarlo para que me verifique que el numero celular existe en la base de datos, si es que existe me bote un mensaje existe el numero de celular cosas asi.

Quisiera a idea o una ayudita de como hacerlo.


Tambien quisiera validar por ejemplo.

Que al ingresar un numero de rpm.


Viene hacer asi


#454545


Que me valide el numero de rpm osea que inicie con el simbolo numeral y que sigan 6 numeros.


Bueno esa es mi duda dejo mi codigo haber en que me puedan ayudar..

GRacias


<?php
include ("logic_pandora.php");
include ("calendariomejorado.htm");
include ("arrays.php");

$obj=new logic_pandora();
$cn=$obj->conectar();
$res=$obj->ejecutarConsulta("select * from celulares order by cod_celular asc");
$reg=mysql_num_rows($res);
?>

<script>
function validar(){
if (isNaN(document.frmcelulares.txt_numcelular.value) ) {
alert("USUARIO:\nEste campo Numero de Celular debe tener NUMEROS.");
document.frmcelulares.txt_numcelular.focus();
return (false);
}
if (isNaN(document.frmcelulares.txtserie_equipo.value )) {
alert("USUARIO:\nEste campo serie equipo debe tener NUMEROS.");
document.frmcelulares.txtserie_equipo.focus();
return (false);
}
if (isNaN(document.frmcelulares.txtserie_chip.value)) {
alert("USUARIO:\nEste campo serie chip debe tener NUMEROS.");
document.frmcelulares.txtserie_chip.focus();
return (false);
}
if (document.frmcelulares.txt_numcelular.value.length ==0){
alert("USUARIO:\nTiene que Ingresar el Numero Celular.")
document.frmcelulares.txt_numcelular.focus()
return (false);
}
if (document.frmcelulares.txtnum_rpm.value.length==0) {
alert("USUARIO:\Tiene que Ingresar el RPM.")
document.frmcelulares.txtnum_rpm.focus()
return (false);

}

if (document.frmcelulares.txtserie_equipo.value.lengt h==0){
alert("USUARIO:\Tiene que Ingresar la serie del equipo .")
document.frmcelulares.txtserie_equipo.focus()
return (false);
}
if (document.frmcelulares.txtnombres.value.length==0) {
alert("USUARIO:\Tiene que Ingresar el nombre .")
document.frmcelulares.txtnombres.focus()
return (false);

}
}
</script>
<?
$cod_cel=$_POST["txt_celulares"]; //Atrapando Valores//
$cod_unidad=$_POST["cbouf"];
$cod_model=$_POST["cbomodcel"];
$cod_delega=$_POST["cbodel"];
$num_celular=$_POST["txt_numcelular"];
$num_rpm=$_POST["txtnum_rpm"];
$serie_equipo=$_POST["txtserie_equipo"];
$estado=$_POST["coboestado"];
$localidad=$_POST["cbolocalidad"];
$serie_chip=$_POST["txtserie_chip"];
$fecha_alta=$_POST["txt_fecalta"];
$fecul_cambio=$_POST["txtfechu_cambio"];
$obser=$_POST["txt_observaciones"];
$nombre=$_POST["txtnombres"];
?>

<script>
function Blokea_Enter(){
var key=window.event.keyCode;//codigo de tecla.
if (key ==13 ){// valor de la tecla enter en ascii
event.returnValue = false;
}
}
</script>
<style type="text/css">
<!--
.Estilo6 {font-size: 16px; font-weight: bold;}
.boton1 { width: 92px;
height: 18px;
background:url(Imagenes/btn1z.PNG);
border: 0px;
}
.boton2 { width: 133px;
height: 18px;
background:url(Imagenes/btn2z.PNG);
}
.Estilo7 {font-size: small; color: #333333;}
.Estilo12 {font-size: 17px; color: #313131;}
.Estilo13 {color: #003399; font-size: 13px; }
.Estilo14 {font-size: 12px;}
.Estilo15 {color: #666666;}
.Estilo18 {font-size: 10px}
.Estilo19 {font-size: 11px}
body,td,th {font-family: Verdana, Arial, Helvetica, sans-serif;}
.Estilo20 {font-size: x-small}
.Estilo23 {font-size: x-small; color: #CC0000; }
.Estilo25 {font-size: 7px}
#form1 table {
text-align: left;
}
-->
</style>
<link href="Plantillas/Enlaces.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="celulares.php" method="post" enctype="multipart/form-data" name="frmcelulares" id="frmcelulares" onSubmit="return validar();">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="738" border="1" align="center">
<tr>
<td width="279">Codigo Celular</td>
<td width="586"><label>
<input name="txt_celulares" type="text" id="txt_celulares" onKeyPress="return Blokea_Enter()" value="<? echo $obj->generarCodigo("celulares","cod_celular","5");?> " size="9" />
</label></td>
</tr>
<tr>
<td>Codigo de Unidad</td>
<td><label>
<select name="cbouf" id="cbouf">
<?php
$rs2=mysql_query("Select * from unidades_funciones order by cod_unidad",$cn);
while($fila2=mysql_fetch_array($rs2)){
echo("<option value='$fila2[0]'>$fila2[1]</option>");
}
?>
</select><td>Codigo Modelo</td>
<td><label>
<?php
echo "<select name='cbomodcel'>";
$ma=mysql_query("Select cod_modelo, descripcion_modelo from modelos");
while($ss=mysql_fetch_array($ma)){
$selected='';
if ($ss[1] == $POST['cbomodcel'] ) { $selected="selected='selected'"; };
echo("<option value='$ss[1]' $selected>$ss[1]</option>");
}
echo "</select>";
?>
<td width="18"> <a href=modelos.php?cod=<? echo $registro[0]; ?> title="Haga click aqui para buscar un: Modelo">
<img src="imagenes/lupa.jpg" width="18" height="17"></label> </tr>
<tr>
<td>Codigo Delegación</td>
<td><label>
<select name="cbodel" id="cbodel">
<?php
$rs4=mysql_query("Select * from ots order by codigo_ot ",$cn);
while($fila4=mysql_fetch_array($rs4)){
echo("<option value='$fila4[0]'>$fila4[1]</option>");
}
?>
</select><td>Numero Celular</td>
<td><label>
<input name="txt_numcelular" type="text" onKeyPress="return Blokea_Enter()" id="txt_numcelular" />
</label></td>
</tr>
<tr>
<td>Numero de RPM</td>
<td><input name="txtnum_rpm" type="text" onKeyPress="return Blokea_Enter()" id="txtnum_rpm" /></td>
</tr>
<tr>
<td>Serie Equipo</td>
<td width="586"><label>
<input type="text" name="txtserie_equipo" onKeyPress="return Blokea_Enter()" id="txtserie_equipo" />
</label></td>
</tr>
<tr>
<td>Serie Chip</td>
<td><label>
<input type="text" name="txtserie_chip" onKeyPress="return Blokea_Enter()" id="txtserie_chip" />
</label></td>
</tr>
<tr>
<td>Estado</td>
<td><label>
<select name="cboestado" id="cboestado">
<?
for($s=0;$estados[$s];$s++){
echo "<option value='$estados[$s]'>$estados[$s]</option>";
}
?>

</select>
</label></td>
</tr>
<tr>
<td>Localidad</td>
<td><label>
<select name="cbolocalidad" id="cbolocalidad">
<?
for($i=0;$dptos[$i];$i++){
echo "<option value='$dptos[$i]'>$dptos[$i]</option>";
}
?>
</select><td>Fecha alta</td>
<td><label>
<input type="text" name="txt_fecalta" id="fc_1233089331" title="YYYY-MM-DD" size="15" readonly="true" value="<?=$listamodi[0]["txt_fecalta"]?>">

<input name="button" type="button" class="BotonCalendar"> <img src="imagenes/Calendario.gif" onClick="displayCalendarFor('fc_1233089331');">

</label></td>
</tr>
<tr>
<td>Fecha Ucambio</td>
<td><label>
<input type="text" name="txtfechu_cambio" id="txtfechu_cambio" title="YYYY-MM-DD" size="15" readonly="true" value="<?=$listamodi[0]["txt_fecalta"]?>">

<input name="button" type="button" class="BotonCalendar"> <img src="imagenes/Calendario.gif" onClick="displayCalendarFor('txtfechu_cambio');">

</label></td>
<tr>
<td>Observaciones</td>
<td><input type="text" name="txt_observaciones" onKeyPress="return Blokea_Enter()" id="txt_observaciones" /></td>
</tr>
<tr>
<td>Nombres</td>
<td><input type="text" name="txtnombres" onKeyPress="return Blokea_Enter()" id="txtnombres" /></td>
</tr>
</table>
<input name="btngrabarc" type="submit" class="boton1" value="Insertar" id="btngrabarc" v>
</form>

</body>
</html>



///Nota todo eso de debe de hacer al darle boton, insertar_celular.. valide .
  #2 (permalink)  
Antiguo 02/07/2009, 12:11
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Problema al validar formulario.

Para validar un valor en la base de datos, primero haz un select verifica si el valor existe y dentro de un

if(){}
else{}

colocas lo que vas a hacer. Si existe en la base de datos envias un mensaje, sino existe añades el numero
  #3 (permalink)  
Antiguo 02/07/2009, 16:33
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Hay una forma de verificarlo mediante java script...
  #4 (permalink)  
Antiguo 02/07/2009, 18:16
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Problema al validar formulario.

Verifica mas bien con ajax
  #5 (permalink)  
Antiguo 03/07/2009, 16:09
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Tio mucho me hablan de ese bendito ajax pero no tengo mucha info de ese ajax mira eh estado indagando como realizar esto y eh encotrado un codigo por ahi..


/Metodo para validar un Numero celular repetido//
if(isset($_POST["btngrabarc"])){
$num_celular=$_POST["txt_numcelular"];

$sql = "SELECT COUNT(*) FROM celulares WHERE num_celular = '$num_celular'";
$consulta = mysql_query($sql, $cn) or die( mysql_error() );
$dato = mysql_result($consulta, 0);

if ($dato >= 1) {
echo "El campo celular ya esta registrado";
} else {


$consulta = mysql_query($sql, $cn) or die( mysql_error() );
}
if(!mysql_error()) {echo "Bien";}
else {echo "Intente mas tarde";}

mysql_close($cn);
}
//



No me arroja ni error de sintaxis ni nada solo que no sale el mensaje ps..


...
Codigo de insertar celulares..



<?php
include ("logic_pandora.php");
include ("calendariomejorado.htm");
include ("arrays.php");

$obj=new logic_pandora();
$cn=$obj->conectar();
$res=$obj->ejecutarConsulta("select * from celulares order by cod_celular asc");
$reg=mysql_num_rows($res);


//Metodo para validar un Numero celular repetido//
if(isset($_POST["btngrabarc"])){
$num_celular=$_POST["txt_numcelular"];

$sql = "SELECT COUNT(*) FROM celulares WHERE num_celular = '$num_celular'";
$consulta = mysql_query($sql, $cn) or die( mysql_error() );
$dato = mysql_result($consulta, 0);

if ($dato >= 1) {
echo "El campo celular ya esta registrado";
} else {


$consulta = mysql_query($sql, $cn) or die( mysql_error() );
}
if(!mysql_error()) {echo "Bien";}
else {echo "Intente mas tarde";}

mysql_close($cn);
}
//


?>

<script>
function validar(){
if (isNaN(document.frmcelulares.txt_numcelular.value) ) {
alert("USUARIO:\nEste campo Numero de Celular debe tener NUMEROS.");
document.frmcelulares.txt_numcelular.focus();
return (false);
}
if (isNaN(document.frmcelulares.txtserie_equipo.value )) {
alert("USUARIO:\nEste campo serie equipo debe tener NUMEROS.");
document.frmcelulares.txtserie_equipo.focus();
return (false);
}
if (isNaN(document.frmcelulares.txtserie_chip.value)) {
alert("USUARIO:\nEste campo serie chip debe tener NUMEROS.");
document.frmcelulares.txtserie_chip.focus();
return (false);
}
if (document.frmcelulares.txt_numcelular.value.length ==0){
alert("USUARIO:\nTiene que Ingresar el Numero Celular.")
document.frmcelulares.txt_numcelular.focus()
return (false);
}
if (document.frmcelulares.txtnum_rpm.value.length==0) {
alert("USUARIO:\Tiene que Ingresar el RPM.")
document.frmcelulares.txtnum_rpm.focus()
return (false);

}

if (document.frmcelulares.txtserie_equipo.value.lengt h==0){
alert("USUARIO:\Tiene que Ingresar la serie del equipo .")
document.frmcelulares.txtserie_equipo.focus()
return (false);
}
if (document.frmcelulares.txtnombres.value.length==0) {
alert("USUARIO:\Tiene que Ingresar el nombre .")
document.frmcelulares.txtnombres.focus()
return (false);

}
}
</script>

<?
$cod_cel=$_POST["txt_celulares"]; //Atrapando Valores//
$cod_unidad=$_POST["cbouf"];
$cod_model=$_POST["cbomodcel"];
$cod_delega=$_POST["cbodel"];
//$num_celular=$_POST["txt_numcelular"];
$num_rpm=$_POST["txtnum_rpm"];
$serie_equipo=$_POST["txtserie_equipo"];
$estado=$_POST["coboestado"];
$localidad=$_POST["cbolocalidad"];
$serie_chip=$_POST["txtserie_chip"];
$fecha_alta=$_POST["txt_fecalta"];
$fecul_cambio=$_POST["txtfechu_cambio"];
$obser=$_POST["txt_observaciones"];
$nombre=$_POST["txtnombres"];
?>

<style type="text/css">
<!--
.Estilo6 {font-size: 16px; font-weight: bold;}
.boton1 { width: 92px;
height: 18px;
background:url(Imagenes/btn1z.PNG);
border: 0px;
}
.boton2 { width: 133px;
height: 18px;
background:url(Imagenes/btn2z.PNG);
}
.Estilo7 {font-size: small; color: #333333;}
.Estilo12 {font-size: 17px; color: #313131;}
.Estilo13 {color: #003399; font-size: 13px; }
.Estilo14 {font-size: 12px;}
.Estilo15 {color: #666666;}
.Estilo18 {font-size: 10px}
.Estilo19 {font-size: 11px}
body,td,th {font-family: Verdana, Arial, Helvetica, sans-serif;}
.Estilo20 {font-size: x-small}
.Estilo23 {font-size: x-small; color: #CC0000; }
.Estilo25 {font-size: 7px}
#form1 table {
text-align: left;
}
-->
</style>
<link href="Plantillas/Enlaces.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="celulares.php" method="post" enctype="multipart/form-data" name="frmcelulares" id="frmcelulares" onSubmit="return validar()">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="738" border="1" align="center">
<tr>
<td width="279">Codigo Celular</td>
<td width="586"><label>
<input name="txt_celulares" type="text" id="txt_celulares" onKeyPress="return Blokea_Enter()" value="<? echo $obj->generarCodigo("celulares","cod_celular","5");?> " size="9" />
</label></td>
</tr>
<tr>
<td>Codigo de Unidad</td>
<td><label>
<select name="cbouf" id="cbouf">
<?php
$rs2=mysql_query("Select * from unidades_funciones order by cod_unidad",$cn);
while($fila2=mysql_fetch_array($rs2)){
echo("<option value='$fila2[0]'>$fila2[1]</option>");
}
?>
</select><td>Codigo Modelo</td>
<td><label>
<?php
echo "<select name='cbomodcel'>";
$ma=mysql_query("Select cod_modelo, descripcion_modelo from modelos");
while($ss=mysql_fetch_array($ma)){
$selected='';
if ($ss[1] == $POST['cbomodcel'] ) { $selected="selected='selected'"; };
echo("<option value='$ss[1]' $selected>$ss[1]</option>");
}
echo "</select>";
?>
<td width="18"> <a href=modelos.php?cod=<? echo $registro[0]; ?> title="Haga click aqui para buscar un: Modelo">
<img src="imagenes/lupa.jpg" width="18" height="17"></label> </tr>
<tr>
<td>Codigo Delegación</td>
<td><label>
<select name="cbodel" id="cbodel">
<?php
$rs4=mysql_query("Select * from ots order by codigo_ot ",$cn);
while($fila4=mysql_fetch_array($rs4)){
echo("<option value='$fila4[0]'>$fila4[1]</option>");
}
?>
</select><td>Numero Celular</td>
<td><label>
<input name="txt_numcelular" type="text" id="txt_numcelular" onKeyPress="return Blokea_Enter()" size="9" maxlength="9" />
</label></td>
</tr>
<tr>
<td>Numero de RPM</td>
<td><input name="txtnum_rpm" type="text" onKeyPress="return Blokea_Enter()" id="txtnum_rpm" /></td>
</tr>
<tr>
<td>Serie Equipo</td>
<td width="586"><label>
<input type="text" name="txtserie_equipo" onKeyPress="return Blokea_Enter()" id="txtserie_equipo" />
</label></td>
</tr>
<tr>
<td>Serie Chip</td>
<td><label>
<input type="text" name="txtserie_chip" onKeyPress="return Blokea_Enter()" id="txtserie_chip" />
</label></td>
</tr>
<tr>
<td>Estado</td>
<td><label>
<select name="cboestado" id="cboestado">
<?
for($s=0;$estados[$s];$s++){
echo "<option value='$estados[$s]'>$estados[$s]</option>";
}
?>

</select>
</label></td>
</tr>
<tr>
<td>Localidad</td>
<td><label>
<select name="cbolocalidad" id="cbolocalidad">
<?
for($i=0;$dptos[$i];$i++){
echo "<option value='$dptos[$i]'>$dptos[$i]</option>";
}
?>
</select><td>Fecha alta</td>
<td><label>
<input type="text" name="txt_fecalta" id="fc_1233089331" title="YYYY-MM-DD" size="15" readonly="true" value="<?=$listamodi[0]["txt_fecalta"]?>">

<input name="button" type="button" class="BotonCalendar"> <img src="imagenes/Calendario.gif" onClick="displayCalendarFor('fc_1233089331');">

</label></td>
</tr>
<tr>
<td>Fecha Ucambio</td>
<td><label>
<input type="text" name="txtfechu_cambio" id="txtfechu_cambio" title="YYYY-MM-DD" size="15" readonly="true" value="<?=$listamodi[0]["txt_fecalta"]?>">

<input name="button" type="button" class="BotonCalendar"> <img src="imagenes/Calendario.gif" onClick="displayCalendarFor('txtfechu_cambio');">

</label></td>
<tr>
<td>Observaciones</td>
<td><input type="text" name="txt_observaciones" onKeyPress="return Blokea_Enter()" id="txt_observaciones" /></td>
</tr>
<tr>
<td>Nombres</td>
<td><input type="text" name="txtnombres" onKeyPress="return Blokea_Enter()" id="txtnombres" /></td>
</tr>
</table>
<input name="btngrabarc" type="submit" class="boton1" value="Insertar" id="btngrabarc" v>
</form>

</body>
</html>









Ayudenme gente .... tengo esta cosa metida en la cabeza denme ideas ya se ke estoy pòr buen camino solo faltan pulir unas cosas.
  #6 (permalink)  
Antiguo 03/07/2009, 16:10
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Tio mucho me hablan de ese bendito ajax pero no tengo mucha info de ese ajax mira eh estado indagando como realizar esto y eh encotrado un codigo por ahi..


/Metodo para validar un Numero celular repetido//
if(isset($_POST["btngrabarc"])){
$num_celular=$_POST["txt_numcelular"];

$sql = "SELECT COUNT(*) FROM celulares WHERE num_celular = '$num_celular'";
$consulta = mysql_query($sql, $cn) or die( mysql_error() );
$dato = mysql_result($consulta, 0);

if ($dato >= 1) {
echo "El campo celular ya esta registrado";
} else {


$consulta = mysql_query($sql, $cn) or die( mysql_error() );
}
if(!mysql_error()) {echo "Bien";}
else {echo "Intente mas tarde";}

mysql_close($cn);
}
//



No me arroja ni error de sintaxis ni nada solo que no sale el mensaje ps..


...
Codigo de insertar celulares..



<?php
include ("logic_pandora.php");
include ("calendariomejorado.htm");
include ("arrays.php");

$obj=new logic_pandora();
$cn=$obj->conectar();
$res=$obj->ejecutarConsulta("select * from celulares order by cod_celular asc");
$reg=mysql_num_rows($res);


//Metodo para validar un Numero celular repetido//
if(isset($_POST["btngrabarc"])){
$num_celular=$_POST["txt_numcelular"];

$sql = "SELECT COUNT(*) FROM celulares WHERE num_celular = '$num_celular'";
$consulta = mysql_query($sql, $cn) or die( mysql_error() );
$dato = mysql_result($consulta, 0);

if ($dato >= 1) {
echo "El campo celular ya esta registrado";
} else {


$consulta = mysql_query($sql, $cn) or die( mysql_error() );
}
if(!mysql_error()) {echo "Bien";}
else {echo "Intente mas tarde";}

mysql_close($cn);
}
//


?>

<script>
function validar(){
if (isNaN(document.frmcelulares.txt_numcelular.value) ) {
alert("USUARIO:\nEste campo Numero de Celular debe tener NUMEROS.");
document.frmcelulares.txt_numcelular.focus();
return (false);
}
if (isNaN(document.frmcelulares.txtserie_equipo.value )) {
alert("USUARIO:\nEste campo serie equipo debe tener NUMEROS.");
document.frmcelulares.txtserie_equipo.focus();
return (false);
}
if (isNaN(document.frmcelulares.txtserie_chip.value)) {
alert("USUARIO:\nEste campo serie chip debe tener NUMEROS.");
document.frmcelulares.txtserie_chip.focus();
return (false);
}
if (document.frmcelulares.txt_numcelular.value.length ==0){
alert("USUARIO:\nTiene que Ingresar el Numero Celular.")
document.frmcelulares.txt_numcelular.focus()
return (false);
}
if (document.frmcelulares.txtnum_rpm.value.length==0) {
alert("USUARIO:\Tiene que Ingresar el RPM.")
document.frmcelulares.txtnum_rpm.focus()
return (false);

}

if (document.frmcelulares.txtserie_equipo.value.lengt h==0){
alert("USUARIO:\Tiene que Ingresar la serie del equipo .")
document.frmcelulares.txtserie_equipo.focus()
return (false);
}
if (document.frmcelulares.txtnombres.value.length==0) {
alert("USUARIO:\Tiene que Ingresar el nombre .")
document.frmcelulares.txtnombres.focus()
return (false);

}
}
</script>

<?
$cod_cel=$_POST["txt_celulares"]; //Atrapando Valores//
$cod_unidad=$_POST["cbouf"];
$cod_model=$_POST["cbomodcel"];
$cod_delega=$_POST["cbodel"];
//$num_celular=$_POST["txt_numcelular"];
$num_rpm=$_POST["txtnum_rpm"];
$serie_equipo=$_POST["txtserie_equipo"];
$estado=$_POST["coboestado"];
$localidad=$_POST["cbolocalidad"];
$serie_chip=$_POST["txtserie_chip"];
$fecha_alta=$_POST["txt_fecalta"];
$fecul_cambio=$_POST["txtfechu_cambio"];
$obser=$_POST["txt_observaciones"];
$nombre=$_POST["txtnombres"];
?>

<style type="text/css">
<!--
.Estilo6 {font-size: 16px; font-weight: bold;}
.boton1 { width: 92px;
height: 18px;
background:url(Imagenes/btn1z.PNG);
border: 0px;
}
.boton2 { width: 133px;
height: 18px;
background:url(Imagenes/btn2z.PNG);
}
.Estilo7 {font-size: small; color: #333333;}
.Estilo12 {font-size: 17px; color: #313131;}
.Estilo13 {color: #003399; font-size: 13px; }
.Estilo14 {font-size: 12px;}
.Estilo15 {color: #666666;}
.Estilo18 {font-size: 10px}
.Estilo19 {font-size: 11px}
body,td,th {font-family: Verdana, Arial, Helvetica, sans-serif;}
.Estilo20 {font-size: x-small}
.Estilo23 {font-size: x-small; color: #CC0000; }
.Estilo25 {font-size: 7px}
#form1 table {
text-align: left;
}
-->
</style>
<link href="Plantillas/Enlaces.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="celulares.php" method="post" enctype="multipart/form-data" name="frmcelulares" id="frmcelulares" onSubmit="return validar()">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="738" border="1" align="center">
<tr>
<td width="279">Codigo Celular</td>
<td width="586"><label>
<input name="txt_celulares" type="text" id="txt_celulares" onKeyPress="return Blokea_Enter()" value="<? echo $obj->generarCodigo("celulares","cod_celular","5");?> " size="9" />
</label></td>
</tr>
<tr>
<td>Codigo de Unidad</td>
<td><label>
<select name="cbouf" id="cbouf">
<?php
$rs2=mysql_query("Select * from unidades_funciones order by cod_unidad",$cn);
while($fila2=mysql_fetch_array($rs2)){
echo("<option value='$fila2[0]'>$fila2[1]</option>");
}
?>
</select><td>Codigo Modelo</td>
<td><label>
<?php
echo "<select name='cbomodcel'>";
$ma=mysql_query("Select cod_modelo, descripcion_modelo from modelos");
while($ss=mysql_fetch_array($ma)){
$selected='';
if ($ss[1] == $POST['cbomodcel'] ) { $selected="selected='selected'"; };
echo("<option value='$ss[1]' $selected>$ss[1]</option>");
}
echo "</select>";
?>
<td width="18"> <a href=modelos.php?cod=<? echo $registro[0]; ?> title="Haga click aqui para buscar un: Modelo">
<img src="imagenes/lupa.jpg" width="18" height="17"></label> </tr>
<tr>
<td>Codigo Delegación</td>
<td><label>
<select name="cbodel" id="cbodel">
<?php
$rs4=mysql_query("Select * from ots order by codigo_ot ",$cn);
while($fila4=mysql_fetch_array($rs4)){
echo("<option value='$fila4[0]'>$fila4[1]</option>");
}
?>
</select><td>Numero Celular</td>
<td><label>
<input name="txt_numcelular" type="text" id="txt_numcelular" onKeyPress="return Blokea_Enter()" size="9" maxlength="9" />
</label></td>
</tr>
<tr>
<td>Numero de RPM</td>
<td><input name="txtnum_rpm" type="text" onKeyPress="return Blokea_Enter()" id="txtnum_rpm" /></td>
</tr>
<tr>
<td>Serie Equipo</td>
<td width="586"><label>
<input type="text" name="txtserie_equipo" onKeyPress="return Blokea_Enter()" id="txtserie_equipo" />
</label></td>
</tr>
<tr>
<td>Serie Chip</td>
<td><label>
<input type="text" name="txtserie_chip" onKeyPress="return Blokea_Enter()" id="txtserie_chip" />
</label></td>
</tr>
<tr>
<td>Estado</td>
<td><label>
<select name="cboestado" id="cboestado">
<?
for($s=0;$estados[$s];$s++){
echo "<option value='$estados[$s]'>$estados[$s]</option>";
}
?>

</select>
</label></td>
</tr>
<tr>
<td>Localidad</td>
<td><label>
<select name="cbolocalidad" id="cbolocalidad">
<?
for($i=0;$dptos[$i];$i++){
echo "<option value='$dptos[$i]'>$dptos[$i]</option>";
}
?>
</select><td>Fecha alta</td>
<td><label>
<input type="text" name="txt_fecalta" id="fc_1233089331" title="YYYY-MM-DD" size="15" readonly="true" value="<?=$listamodi[0]["txt_fecalta"]?>">

<input name="button" type="button" class="BotonCalendar"> <img src="imagenes/Calendario.gif" onClick="displayCalendarFor('fc_1233089331');">

</label></td>
</tr>
<tr>
<td>Fecha Ucambio</td>
<td><label>
<input type="text" name="txtfechu_cambio" id="txtfechu_cambio" title="YYYY-MM-DD" size="15" readonly="true" value="<?=$listamodi[0]["txt_fecalta"]?>">

<input name="button" type="button" class="BotonCalendar"> <img src="imagenes/Calendario.gif" onClick="displayCalendarFor('txtfechu_cambio');">

</label></td>
<tr>
<td>Observaciones</td>
<td><input type="text" name="txt_observaciones" onKeyPress="return Blokea_Enter()" id="txt_observaciones" /></td>
</tr>
<tr>
<td>Nombres</td>
<td><input type="text" name="txtnombres" onKeyPress="return Blokea_Enter()" id="txtnombres" /></td>
</tr>
</table>
<input name="btngrabarc" type="submit" class="boton1" value="Insertar" id="btngrabarc" v>
</form>

</body>
</html>









Ayudenme gente .... tengo esta cosa metida en la cabeza denme ideas ya se ke estoy pòr buen camino solo faltan pulir unas cosas.
  #7 (permalink)  
Antiguo 03/07/2009, 16:30
Avatar de cesarpunk  
Fecha de Ingreso: enero-2008
Ubicación: Lima
Mensajes: 943
Antigüedad: 16 años, 3 meses
Puntos: 9
Respuesta: Problema al validar formulario.

la forma de verificar datos es sencilla , hazlo con mysql_num_rows() que te busca el numero de registros que te salen de una consulta

Código PHP:

//recojes el numero de celular:

$celular $_POST['celular'];

$sql="select * from celular where cel_numero=".$celular;
$rs=mysql_query($sql);

//traes el número de registros que da la consulta
$existe=mysql_num_rows($e_sql);

//SI TE SALE 1 ES PORQUE HAY UN REGISTRO... SI SALE 0 PORQUE NO EXISTE

if($existe==0){
   
//guardas el celular con el dato que tienes $celular
}
else{
   
//mandas el error que quieres

espero entiendas esta logica que es muy simple.

P.d. : si no se ajax... estoy condenado?
__________________
Quitenme la vida pero no la bebida.
  #8 (permalink)  
Antiguo 03/07/2009, 16:36
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Ok tio lo chekiare ps ... si la entiendo lo que sucede es que no me bota el mensaje cuano le doy clic al boton insertar.
  #9 (permalink)  
Antiguo 03/07/2009, 16:50
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Probe el codigo y no me sale el mensaje y me sigue guardando el mismo numero repetido.

No entiendo en que fallo.



//Metodo para validar un Numero celular repetido//
if(isset($_POST["btngrabarc"])){
//recojes el numero de celular:

$num_celular = $_POST['txt_numcelular'];

$sql="select * from celulares where num_celular=".$num_celular;
$rs=mysql_query($sql);

//traes el número de registros que da la consulta
$existe=mysql_num_rows($e_sql);

//SI TE SALE 1 ES PORQUE HAY UN REGISTRO... SI SALE 0 PORQUE NO EXISTE

if($existe==0){
$obj->GrabarCelular($_POST["txt_celulares"],$_POST["cbouf"],$cod_modelo,$_POST["cbodel"],$_POST["txt_numcelular"],$_POST["txtnum_rpm"],$_POST["txtserie_equipo"],$_POST["txtserie_chip"],strtoupper($_POST["cboestado"]),strtoupper($_POST["cbolocalidad"]),$_POST["txt_fecalta"],$_POST["txtfechu_cambio"],strtoupper($_POST["txt_observaciones"]),strtoupper($_POST["txtnombres"]));
//guardas el celular con el dato que tienes $celular
}
else{
echo"El campo celular ya esta registrado";
echo "existe".$existe;

}
}

?>
  #10 (permalink)  
Antiguo 03/07/2009, 17:21
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Respuesta: Problema al validar formulario.

investiga sobre mysq_num_rows y ereg()

saludos
__________________
*La amistad se multiplica cuando se divide*
  #11 (permalink)  
Antiguo 03/07/2009, 17:25
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Mil gracias ya resolvi mi problema ....

$num_celular=$_POST["txt_numcelular"];

$sql = "SELECT num_celular FROM celulares WHERE num_celular = '$num_celular'";
$consulta = mysql_query($sql, $cn) or die( mysql_error() );


if (mysql_num_rows($consulta) >= 1) {
die ("El campo celular ya esta registrado");
}


Pero tengo una duda hermano, yo lo tgo esto en un formulario osea valida chevere pero al darle clic a insertar se envia a otra pagina llmada celulares.

Me expliko..

esta linea de la cab del form con propiedades esta en mi pagina que estoy ke valido.

El asunto es que valida cuando esto es asi <form action="" osea vacio...
pero cuando esta <form action="celulares.php" no valida-... y se graba el mismo repetido .. no habra una forma de crear u función o llamarla... porque yo trabjo asi con muchas paginas..

<form action="" method="post" enctype="multipart/form-data" name="frmcelulares" id="frmcelulares"


Llamar a una función tipo java con el submit o en el keypress de la caja se me a ocurrido... pero como eso se hace en java pero en php...
  #12 (permalink)  
Antiguo 03/07/2009, 17:29
 
Fecha de Ingreso: febrero-2006
Mensajes: 858
Antigüedad: 18 años, 2 meses
Puntos: 4
Respuesta: Problema al validar formulario.

noo la vdd no te entendi explicate mejor porfa

saludos
__________________
*La amistad se multiplica cuando se divide*
  #13 (permalink)  
Antiguo 03/07/2009, 17:35
Avatar de cesarpunk  
Fecha de Ingreso: enero-2008
Ubicación: Lima
Mensajes: 943
Antigüedad: 16 años, 3 meses
Puntos: 9
Respuesta: Problema al validar formulario.

Supongo que estas validando con php verdad??? ya, si tu estas poniendo form=" " eso significa que todas tus validaciones estan en la misma pagina... pero el proceso de insertar lo estas haciendo en otra pagina...

Ya pues , entonces tus validaciones ponlas en la pagina donde registras, por ejemplo en guardar.php , haces tus validaciones y si todas las condiciones que pones son correctas, grabas y listo. Tal y como te lo explique en el ejemplo anterior:

Código PHP:
if($existe==0){ 
   
//guardas el celular con el dato que tienes $celular 

else{ 
   
//mandas el error que quieres 

__________________
Quitenme la vida pero no la bebida.
  #14 (permalink)  
Antiguo 06/07/2009, 12:07
Avatar de dquispe  
Fecha de Ingreso: mayo-2009
Ubicación: Lima
Mensajes: 232
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Problema al validar formulario.

Gracias solucionado.

Pongo el codigo haber si le ayuda a alguien.


if(isset($_POST["btngrabarc"])){
$num_celular=$_POST["txt_numcelular"];

$sql = "SELECT num_celular FROM celulares WHERE num_celular = '$num_celular'";
$consulta = mysql_query($sql, $cn) or die( mysql_error() );
if (mysql_num_rows($consulta) >= 1) {
echo "<script language='JavaScript'>alert('El Numero celular ya esta registrado')</script>";
exit;

}
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:59.