agrega enblanco
Publicado por cota (16 intervenciones) el 27/04/2010 20:41:44
lo que pasa es lo siguiente que esty haciendo un formulario para que se llenen y agrege los compos , pero le doy agregar sin llenar los campos y se agrega un campo vacio que puedo hacer para que no se agrege aca les mandao el codigo para que me diga que he puesto si es que alguien me puede ayudar hay dos paginas que estan incluiada una que es conecion y la otra es fechan
--- conecion ----
<?php
$conecion=mysql_connect("localhost","root","");
mysql_select_db("php",$conecion);
?>
--------- termina conecion ----
---- fechan --------
<?php
function formatearfecha($fecha)
{
$fecha= explode("/",$fecha);
$fecha=$fecha[2]."-".$fecha[1]."-".$fecha[0];
return $fecha;
}
?>
---------termina fechan------
<?php
session_start();
?>
<!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>
<link href="/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js">
</script>
<script typpe="txt/javascript">
function validarformulario ( )
{
if (document.forms[0].nick.vale=="")
{ alert ( "debe ingresar un nick ");
return false;
}
else if (document.forms[0].clave.value.length==0)
{ alert ( "debe ingresar una clave");
return false ;
}
else if (document.forms[0].nombre.value=="")
{ alert ( "debe ingresar una nombre");
return false ;
}
else if (document.forms[0].correo.value=="")
{ alert ( "debe ingresar una correo");
return false ;
}
else if (document.forms[0].fecha.value=="")
{ alert ( "debe ingresar una fecha");
}
else
{
document.forms[0].submit();
}
}
</script>
<title>Documento sin título</title>
</head>
<body>
<?php
include ("conecion.php");
$consulta=mysql_query("select * from usuario where id_usuario=" .$_GET["id"],$conecion);
$rsConsulta=mysql_fetch_array($consulta);
include ("fechan.php");
if (isset($_POST["btngrabar"]))
{
$nick=$_POST["nick"];
$clave=$_POST["clave"];
$nombre=$_POST["nombre"];
$coreo=$_POST["correo"];
$estado=$_POST["estado"];
$fecha=formatearfecha($_POST["fecha"]);
$id=$_POST["txtid"];
$insertar =mysql_query("INSERT INTO usuario (nick_usuario,clave_usuario,nombre_usuario,coreo_usuario,estado_usuario, fecha) values( '$nick' ,'$clave','$nombre','$coreo','$estado','$fecha')",$conecion);
if ($insertar)
{
header ("location:lista.php");
}
else
{
echo "error";
}
}
?>
<form action="" method="post">
<p>nick
<input type ="text" name="nick" id="nick" maxlength ="5"/>
<br/>
clave
<input type ="password" name="clave" id="clave" maxlength ="5"/>
<br/>
nombre
<input type ="text" name ="nombre" id="nombre" maxlength ="22"/>
<br/>
correo
<input type ="text" name ="correo" id="correo"
/>
<br />
estado
<select name="estado" >
<option value="1" selected="selected">activo</option>
<option value="0">inactivo</option>
</select>
<br/>
fecha
<input type ="text" name ="fecha" id="fecha" maxlength="0"
/>
<input type="button" id="button" value="..." onclick="displayCalendar(document.forms[0].fecha,'dd/mm/yyyy',this);"/>
<p>
<input type="submit" name="btngrabar" id="btngrabar" value="Agregar" />
<input type="submit" name="btncancelar" id="btncancelar" value="cancelar" />
<input type="hidden" name="txtid"
value= "<?php echo $rsConsulta["id_usuario"];?>"/>
</form>
--- conecion ----
<?php
$conecion=mysql_connect("localhost","root","");
mysql_select_db("php",$conecion);
?>
--------- termina conecion ----
---- fechan --------
<?php
function formatearfecha($fecha)
{
$fecha= explode("/",$fecha);
$fecha=$fecha[2]."-".$fecha[1]."-".$fecha[0];
return $fecha;
}
?>
---------termina fechan------
<?php
session_start();
?>
<!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>
<link href="/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js">
</script>
<script typpe="txt/javascript">
function validarformulario ( )
{
if (document.forms[0].nick.vale=="")
{ alert ( "debe ingresar un nick ");
return false;
}
else if (document.forms[0].clave.value.length==0)
{ alert ( "debe ingresar una clave");
return false ;
}
else if (document.forms[0].nombre.value=="")
{ alert ( "debe ingresar una nombre");
return false ;
}
else if (document.forms[0].correo.value=="")
{ alert ( "debe ingresar una correo");
return false ;
}
else if (document.forms[0].fecha.value=="")
{ alert ( "debe ingresar una fecha");
}
else
{
document.forms[0].submit();
}
}
</script>
<title>Documento sin título</title>
</head>
<body>
<?php
include ("conecion.php");
$consulta=mysql_query("select * from usuario where id_usuario=" .$_GET["id"],$conecion);
$rsConsulta=mysql_fetch_array($consulta);
include ("fechan.php");
if (isset($_POST["btngrabar"]))
{
$nick=$_POST["nick"];
$clave=$_POST["clave"];
$nombre=$_POST["nombre"];
$coreo=$_POST["correo"];
$estado=$_POST["estado"];
$fecha=formatearfecha($_POST["fecha"]);
$id=$_POST["txtid"];
$insertar =mysql_query("INSERT INTO usuario (nick_usuario,clave_usuario,nombre_usuario,coreo_usuario,estado_usuario, fecha) values( '$nick' ,'$clave','$nombre','$coreo','$estado','$fecha')",$conecion);
if ($insertar)
{
header ("location:lista.php");
}
else
{
echo "error";
}
}
?>
<form action="" method="post">
<p>nick
<input type ="text" name="nick" id="nick" maxlength ="5"/>
<br/>
clave
<input type ="password" name="clave" id="clave" maxlength ="5"/>
<br/>
nombre
<input type ="text" name ="nombre" id="nombre" maxlength ="22"/>
<br/>
correo
<input type ="text" name ="correo" id="correo"
/>
<br />
estado
<select name="estado" >
<option value="1" selected="selected">activo</option>
<option value="0">inactivo</option>
</select>
<br/>
fecha
<input type ="text" name ="fecha" id="fecha" maxlength="0"
/>
<input type="button" id="button" value="..." onclick="displayCalendar(document.forms[0].fecha,'dd/mm/yyyy',this);"/>
<p>
<input type="submit" name="btngrabar" id="btngrabar" value="Agregar" />
<input type="submit" name="btncancelar" id="btncancelar" value="cancelar" />
<input type="hidden" name="txtid"
value= "<?php echo $rsConsulta["id_usuario"];?>"/>
</form>
Valora esta pregunta


0