Ver Mensaje Individual
  #4 (permalink)  
Antiguo 21/12/2016, 15:31
JESUMINISTROSYMAS
(Desactivado)
 
Fecha de Ingreso: septiembre-2008
Ubicación: Maracay edo Aragua Venezuela
Mensajes: 48
Antigüedad: 15 años, 8 meses
Puntos: 3
Pregunta Respuesta: Hacer UPDATE en una tabla e INSERT a otra tabla

Ampliare lo que tengo:

INDEX:PHP
Código PHP:
<?php
require_once 'usuario.entidad.php';
require_once 
'usuario.model.php';

// Logica
$alm = new Usuario();
$model = new UsuarioModel();

if(isset(
$_REQUEST['action']))
{
    switch(
$_REQUEST['action'])
    {
        case 
'actualizar':
            
$alm->__SET('id',          $_REQUEST['id']);
            
$alm->__SET('Rif',         $_REQUEST['Rif']);
            
$alm->__SET('Nombre',      $_REQUEST['Nombre']);
            
$alm->__SET('Producto',    $_REQUEST['Producto']);
            
$alm->__SET('sistema_enc'$_REQUEST['sistema_enc']);
            
$alm->__SET('nro_cupon',   $_REQUEST['nro_cupon']);
            
$alm->__SET('fecha_envio'$_REQUEST['fecha_envio']);
            
$alm->__SET('nota',        $_REQUEST['nota']);

            
$model->Actualizar($alm);
            
header('Location: index.php');
            break;

        case 
'registrar':
            
$alm->__SET('Rif',          $_REQUEST['Rif']);
            
$alm->__SET('Nombre',       $_REQUEST['Nombre']);
            
$alm->__SET('Producto',     $_REQUEST['Producto']);
            
$alm->__SET('sistema_enc',  $_REQUEST['sistema_enc']);
            
$alm->__SET('nro_cupon',    $_REQUEST['nro_cupon']);
            
$alm->__SET('fecha_envio',  $_REQUEST['fecha_envio']);
            
$alm->__SET('nota',         $_REQUEST['nota']);

            
$model->Registrar($alm);
            
header('Location: index.php');
            break;        

        case 
'eliminar':
            
$model->Eliminar($_REQUEST['id']);
            
header('Location: index.php');
            break;

        case 
'editar':
            
$alm $model->Obtener($_REQUEST['id']);
            break;
    }
}

?>

<!DOCTYPE html>
<html lang="es">
<head>
    <title>SIGENVIOS</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" >
    <link rel="stylesheet" type="text/css" href="../../../admin/config/css/estilo2.css">
</head>
    <body style="padding:15px;">

        <div class="pure-g">
            <div class="pure-u-1-12">
                
                <form action="?action=<?php echo $alm->id 'actualizar' 'registrar'?>" method="post" class="pure-form "style="margin-bottom:30px;">
                    <input type="hidden" name="id" value="<?php echo $alm->__GET('id'); ?>" />
                    
                    <table style="width:500px;">
                        <tr>
                            <th style="text-align:left;">Rif</th>
                            <td><input type="text" name="Rif" value="<?php echo $alm->__GET('Rif'); ?>" style="width:100%;" /></td>
                        </tr>
                        <tr>
                            <th style="text-align:left;">Nombre</th>
                            <td><input type="text" name="Nombre" value="<?php echo $alm->__GET('Nombre'); ?>" style="width:100%;" /></td>
                        </tr>
AQUI VA EL RESTO DEL FORMULARIO LO BORRE POR SER MUY LARGO
                        <tr>
                            <td colspan="2">
                                <button type="submit" class="pure-button pure-button-primary">Guardar</button>
                            </td>
                        </tr>
                    </table>
                </form>

                <table class="pure-table pure-table-horizontal">
                    <thead>
                        <tr>
                            <th style="text-align:left;">Rif</th>
                            <th style="text-align:left;">Nombre</th>
                            <th style="text-align:left;">Producto</th>
                            <th style="text-align:left;">Encomienda</th>
                            <th style="text-align:left;">Nro Cupon</th>
                            <th style="text-align:left;">Fecha Envio</th>
                            <th style="text-align:left;">Nota</th>
                            <th></th>
                            <th></th>
                        </tr>
                    </thead>
                    <?php foreach($model->Listar() as $r): ?>
                        <tr>
                            <td><?php echo $r->__GET('Rif'); ?></td>
                            <td><?php echo $r->__GET('Nombre'); ?></td>
                            <td><?php echo $r->__GET('Producto'); ?></td>
                            <td><?php echo $r->__GET('sistema_enc'); ?></td>
                            <td><?php echo $r->__GET('nro_cupon'); ?></td>
                            <td><?php echo $r->__GET('fecha_envio'); ?></td>
                            <td><?php echo $r->__GET('nota'); ?></td>
                            <td>
                                <a href="?action=editar&id=<?php echo $r->id?>">Editar</a>
                            </td>
                            <td>
 <!-- esta linea activa la opcion de borrar row de mysql-->
 <a href="?action=eliminar&id=<?php echo $r->id?>">Eliminar</a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </table>     
              
            </div>
        </div>

    </body>
</html>
USUARIO.MODEL.PHP
Código PHP:
<?php
class UsuarioModel
{
    private 
$pdo;

    public function 
__CONSTRUCT()
    {
        try
        {
            
$this->pdo = new PDO('mysql:host=localhost;dbname=datos''MI USUARIO''MI CLAVE');

            
$this->pdo->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);                
        }
        catch(
Exception $e)
        {
            die(
$e->getMessage());
        }
    }

    public function 
Listar()
    {
        try
        {
            
$result = array();

            
$stm $this->pdo->prepare("SELECT * FROM ingreso ORDER BY id DESC  LIMIT 5");
            
$stm->execute();

            foreach(
$stm->fetchAll(PDO::FETCH_OBJ) as $r)
            {
                
$alm = new Usuario();

                
$alm->__SET('id'$r->id);
                
$alm->__SET('Rif'$r->rif);
                
$alm->__SET('Nombre'$r->nombre);
                
$alm->__SET('Producto'$r->producto);
                
$alm->__SET('sistema_enc'$r->sistema_enc);
                
$alm->__SET('nro_cupon'$r->nro_cupon);
                
$alm->__SET('fecha_envio'$r->fecha_envio);
                
$alm->__SET('nota'$r->nota);

                
$result[] = $alm;
            }

            return 
$result;
        }
        catch(
Exception $e)
        {
            die(
$e->getMessage());
        }
    }

    public function 
Obtener($id)
    {
        try 
        {
            
$stm $this->pdo
                      
->prepare("SELECT * FROM ingreso WHERE id = ?");
                      

            
$stm->execute(array($id));
            
$r $stm->fetch(PDO::FETCH_OBJ);

            
$alm = new Usuario();

                
$alm->__SET('id'$r->id);
                
$alm->__SET('Rif'$r->rif);
                
$alm->__SET('Nombre'$r->nombre);
                
$alm->__SET('Producto'$r->producto);
                
$alm->__SET('sistema_enc'$r->sistema_enc);
                
$alm->__SET('nro_cupon'$r->nro_cupon);
                
$alm->__SET('fecha_envio'$r->fecha_envio);
                
$alm->__SET('nota'$r->nota);

            return 
$alm;
        } catch (
Exception $e
        {
            die(
$e->getMessage());
        }
    }

    public function 
Eliminar($id)
    {
        try 
        {
            
$stm $this->pdo
                      
->prepare("DELETE FROM ingreso WHERE id = ?");                      

            
$stm->execute(array($id));
        } catch (
Exception $e
        {
            die(
$e->getMessage());
        }
    }

    public function 
Actualizar(Usuario $data)
    {
        try 
        {
            
$sql "UPDATE ingreso SET 
                        rif          = ?, 
                        nombre        = ?,
                        producto            = ?, 
                        sistema_enc = ?,
                        nro_cupon = ?,
                        fecha_envio = ?,
                        nota = ?
                    WHERE id = ?"
;

            
$this->pdo->prepare($sql)
                 ->
execute(
                array(
                    
$data->__GET('Rif'), 
                    
$data->__GET('Nombre'), 
                    
$data->__GET('Producto'),
                    
$data->__GET('sistema_enc'),
                    
$data->__GET('nro_cupon'),
                    
$data->__GET('fecha_envio'),
                    
$data->__GET('nota'),
                    
$data->__GET('id')
                    
                    )
                            
                );
        }
        
        
        catch (
Exception $e
        {
            die(
$e->getMessage());
        }
    }

    public function 
Registrar(Usuario $data)
    {
        try 
        {
        
$sql "INSERT INTO ingreso (rif,nombre,producto,sistema_enc,nro_cupon,fecha_envio,nota) 
                VALUES (?, ?, ?, ?, ?, ?, ?)"
;

        
$this->pdo->prepare($sql)
             ->
execute(
            array(
                    
$data->__GET('Rif'), 
                    
$data->__GET('Nombre'), 
                    
$data->__GET('Producto'),
                    
$data->__GET('sistema_enc'),
                    
$data->__GET('nro_cupon'),
                    
$data->__GET('fecha_envio'),
                    
$data->__GET('nota'),
                )
            );
        } catch (
Exception $e
        {
            die(
$e->getMessage());
        }
    }

    
}
USUARIO.ENTIDAD.PHP
Código PHP:
<?php
class Usuario
{
    private 
$id;
    private 
$rif;
    private 
$nombre;
    private 
$producto;
    private 
$sistema_enc;
    private 
$nro_cupon;
    private 
$fecha_envio;
    private 
$nota;


    public function 
__GET($k){ return $this->$k; }
    public function 
__SET($k$v){ return $this->$k $v; }
}
Se que posiblemente para algunas personas sea super sencillo, ya he buscado en varios foros sin exito.

Yo deseo que cuando se active el boton guardar tambien en mi tabla "vitacora" se guarde solo los datos rif y nota con la respectiva fecha de cuando se creo dicho reporte.