/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Registrosocio();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Registrosocio'])) {
         $model->attributes = $_POST['Registrosocio'];
         if ($model->save()) {
             $tiempo = $model->tiempo;
             $entrada = $model->entrada;
             ////funcion sumar
             function sumarMinutosFecha($FechaStr, $MinASumar)
             {
                 $FechaStr = str_replace("-", " ", $FechaStr);
                 $FechaStr = str_replace(":", " ", $FechaStr);
                 $FechaOrigen = explode(" ", $FechaStr);
                 $Dia = $FechaOrigen[2];
                 $Mes = $FechaOrigen[1];
                 $Ano = $FechaOrigen[0];
                 $Horas = $FechaOrigen[3];
                 $Minutos = $FechaOrigen[4];
                 $Segundos = $FechaOrigen[5];
                 // Sumo los minutos
                 $Minutos = (int) $Minutos + (int) $MinASumar;
                 // Asigno la fecha modificada a una nueva variable
                 $FechaNueva = date("Y-m-d H:i:s", mktime($Horas, $Minutos, $Segundos, $Mes, $Dia, $Ano));
                 return $FechaNueva;
             }
             $salida = sumarMinutosFecha($entrada, $tiempo);
             $id = $model->id;
             $link = mysqli_connect("localhost", "root", "root", "bolera");
             $sql = "UPDATE registrosocio SET salida='{$salida}' WHERE id='{$id}'";
             mysqli_query($link, $sql);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
     $this->renderPartial('/site/buscarsalida');
 }
Beispiel #2
0
$rs = mysql_query("SELECT MAX(id) AS id FROM grupos");
if ($row = mysql_fetch_row($rs)) {
    $id = trim($row[0]);
}
$id = $id + 1;
// put your code here
if (isset($_POST['submit'])) {
    // $id=  mysql_query("SELECT MAX(id) AS id FROM grupos;");
    foreach ($_POST['nombre'] as $key => $nombre) {
        $sql = "INSERT INTO chicos(group_id,nombre,apellidos,fecha,padres,telefono) VALUES ('{$id}','{$nombre}','" . $_POST['apellidos'][$key] . "','" . $_POST['fecha'][$key] . "','" . $_POST['padres'][$key] . "','" . $_POST['telefono'][$key] . "');";
        $result1 = mysql_query($sql);
    }
    $alias = $_POST['alias'];
    $entrada = date("Y-m-d H:i:s");
    $tiempo = $_POST['tiempo'];
    $salida = sumarMinutosFecha($entrada, $tiempo);
    $tarifa = $_POST['tarifa'];
    $color = $_POST['color'];
    $hoy = date("Y-m-d");
    $sql2 = "INSERT INTO grupos(alias,entrada,tiempo,salida,total,color,hoy) VALUES('{$alias}','{$entrada}','{$tiempo}','{$salida}','{$tarifa}','{$color}','{$hoy}');";
    $result = mysql_query($sql2) or die(mysql_error());
    if ($result1 && $result) {
        ?>
 <script> alert("Chicos Guardados"); </script> <?php 
    } else {
        ?>
<script> alert("Chicos No guardados pruebe otra vez"); </script><?php 
    }
    $id = 0;
}
?>