en este código se encuentra el formulario que esta dentro del DIV que se llama cuerpo. es algo parecido a cuando usamos los frames.
Código :
<?php
include("conectar.php");
?>
<html><head>
<script language="javascript">
function guardar(){
document.registro.operacion.value="G";
document.registro.method="post";
document.registro.action="registro.php";
document.registro.submit();
}
</script>
</head>
<?php
if($_POST["operacion"]=="G"){
$obj = new formulario(
$_POST["nombre"], $_POST["apellido"], $_POST["cedula"], $_POST["direccion"], $_POST["telefono"], $_POST["codigo"], $_POST["usuario"], $_POST["clave"], $_POST["correo"]);
$result = $obj->agregar();
if($result !=0){
echo "<script language='javascript'>alert('se inserto el registro'); </script>";
}else
echo "<script language='javascript'>alert('error intente nuevamnete'); </script>";
}
?>
<body>
<form name="registro">
<table width="200" border="0">
<tr>
<th colspan="2"> REGISTRO DE USUARIOS</th>
</tr>
<tr>
<td width="40">Nombre:</td>
<td width="144"><input type='text' name='nombre' value="<?php echo $nombre; ?>"></td>
</tr>
<tr>
<td>Apellido:</td>
<td><input type='text' name='apellido' value="<?php echo $apellido; ?>"></td>
</tr>
<tr>
<td>Cedula:</td>
<td><input type='text' name='cedula' value="<?php echo $cedula; ?>"></td>
</tr>
<tr>
<td>Direccion:</td>
<td><input type='text' name='direccion' value="<?php echo $direccion; ?>"></td>
</tr>
<tr>
<td>Telefono:</td>
<td><input type='text' name='telefono' value="<?php echo $telefono; ?>"></td>
</tr>
<!-- <tr>
<td>Codigo:</td>
<td><input type='text' name='codigo' value="<?php echo $codigo; ?>"></td>
</tr> -->
<tr>
<td>Usuario:</td>
<td><input type='text' name='usuario' value="<?php echo $usuario; ?>"> </td>
</tr>
<tr>
<td>Clave:</td>
<td><input type='text' name='clave' value="<?php echo $clave; ?>"></td>
</tr>
<tr>
<td>Correo:</td>
<td><input type='text' name='correo' value="<?php echo $correo; ?>"></td>
</tr>
<tr>
<td colspan="2"><center><input onClick="guardar()" name="boton" type="button" value="enviar"></center></td>
</tr>
</table>
<input type="hidden" name="operacion" value="<?php $operacion; ?>" >
</form>
</body>
</html>
En este código tengo la clase obvio php donde esta la vida de mi pagina.
Código PHP :
<?php
class clasemysql{
private $NOMBREBASEDATO;
private $SERVIDOR;
private $USUARIO;
private $CLAVE;
private $IDCONEX;
private $IDCONSUL;
function __construct(){
$this->SERVIDOR = "localhost";
$this->USUARIO = "root";
$this->CLAVE = "123456";
$this->NOMBREBASEDATO = "db_taxi";
}
function conectar(){
$this->IDCONEX = mysql_connect( $this->SERVIDOR, $this->USUARIO, $this->CLAVE);
if($this->IDCONEX !=0){
mysql_select_db($this->NOMBREBASEDATO, $this->IDCONEX);
}
return $this->IDCONEX;
}
function consultar($sql){
$this->IDCONSUL = mysql_query($sql); /* retorna dependiendo si es un select un resulset y si es un insert envia 0 o 1 */
return $this->IDCONSUL;
}
function desconectar(){
mysql_close($this->IDCONEX);
}
function numRegistro(){
return mysql_num_rows($this->IDCONSUL);
}
}
class formulario extends clasemysql{
private $NOMBRE;//todo esto es en mayuscula
private $APELLIDO;
private $CEDULA;
private $DIRECCION;
private $TELEFONO;
private $CODIGO;
private $USUARIO;
private $CLAVE;
private $CORREO;
function __construct($nombre, $apellido, $cedula, $direccion, $telefono, $codigo, $usuario, $clave, $correo)
{
$this->NOMBRE = $nombre;
$this->APELLIDO = $apellido;
$this->CEDULA = $cedula;
$this->DIRECCION = $direccion;
$this->TELEFONO = $telefono;
$this->CODIGO = $codigo;
$this->USUARIO = $usuario;
$this->CLAVE = $clave;
$this->CORREO = $correo;
parent::__construct();
}
function agregar(){
$result = parent::conectar();
if($result !=0){
$sql = "SELECT * FROM usuario WHERE cedula=".self::getCedula();
$resultado = parent::consultar($sql);
if(numRegistro() == 0){
$sql = "INSERT INTO usuarios VALUES
('".self::getNombre()."', '".self::getApellido()."', ".self::getCedula().", '".self::getDireccion()."', ".self::getTelefono().", ".self::getCodigo().", '".self::getUsuario()."', '".self::getClave()."', '".self::getCorreo()."')";
$resultado = parent::consultar($sql);//captura el valor q retorno consulta si es 0
//no se agrego si es 1 se agrego la persona
}else{
echo "Registro previamente";
}
}
return $resultado;
}
function getNombre(){
return $this->NOMBRE;}
function getApellido(){
return $this->APELLIDO;}
function getCedula(){
return $this->CEDULA;}
function getDireccion(){
return $this->DIRECCION;}
function getTelefono(){
return $this->TELEFONO;}
function getCodigo(){
return $this->CODIGO;}
function getUsuario(){
return $this->USUARIO;}
function getClave(){
return $this->CLAVE;}
function getCorreo(){
return $this->CORREO;}
function eliminar(){
$result = parent::conectar();
if($result !=0){
$sql = " DELETE FROM usuarios WHERE cedula= ".self::getCedula()."; ";
$resultado = parent::consultar($sql);//captura el valor q retorno consulta si es 0
//no se agrego si es 1 se agrego la persona
}
return $resultado;
}
function generacodigo(){
$codigo = substr( $nombre, 0, 1);
$codigo .= substr( $apellido, 0, 1);
//Verifica por consulta SQL cuandos registros llevas Ejemplo llevas 4 codigos de personas registrado...
if(parent::numrows()<10){
$codigo .= "0".parent::numrows();
}else{
$codigo .= parent::numrows();
}
}
}
?>
muchas gracias por detenerse a leer y espero que me puedan echar una mano.
