Ver Mensaje Individual
  #3 (permalink)  
Antiguo 15/10/2010, 09:55
gerson_odir
 
Fecha de Ingreso: octubre-2010
Mensajes: 25
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Insertar Fechas en mysql

estos son los codigos que uso para mas informacion de mi logica primitiva jaja bueno aqui les va

//conectamysql.php ---- funcion para conectar a la base de datos
<?
function conectarse ($user,$pas,$bdd)
{
$link= mysqli_connect('localhost',$user,$pas,$bdd);
if (!$link)
{
echo "No Hay Conexion";
}
return $link;
}
?>



//registro.php

<?
include("conectamysql.php");
$conexion=conectarse("root","","db");
$rs=mysqli_query($conexion, "select * from registro where nombre='$tnombre'");
$num=mysqli_num_rows($rs);
if($num>0)
{
$row=mysqli_fetch_array($rs);
echo "El codigo pertenece a otro ".$row["nombre"];
exit();
}
else
{
if($rs2=mysqli_query($conexion,"INSERT INTO registro(nombre,fecha) VALUES ('$tnombre','$tfecha')")==true)
{
echo "Datos adicionados correctamente";
}
else
{
echo "Ocurrio un error al adicionar el registro";
}
}
mysqli_free_result($rs);
?>



//formulario html

<!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=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="registro.php">
<table width="200" border="1">
<tr>
<td>Nombre</td>
<td><label>
<input type="text" name="tnombre" id="tnombre" />
</label></td>
</tr>
<tr>
<td>Fecha</td>
<td><label>
<input type="text" name="tfecha" id="tfecha" />
</label></td>
</tr>
<tr>
<td><label>
<input type="submit" name="button" id="button" value="aceptar" />
</label></td>
<td><label>
<input type="reset" name="button2" id="button2" value="cancelar" />
</label></td>
</tr>
</table>
</form>
</body>
</html>