Date with php time

0

I would like help with this code, I do not want to save date and time and date.

follow code:

<? include "conexion.php";
 if(isset($_POST['submit'])) {    
   $data = str_replace($_POST['data']); 

   $data_cadastro = $data;  

   $hora_inicio = "07:45:00";
   $hora_final = "09:00:00";   
    $ini = strtotime($hora_inicio); 
    $fim = strtotime($hora_final); 

    $atu = $ini; $i = 0; for ($atu = $ini; 
    $atu < $fim; $atu = strtotime('+15 minutes', $atu)) { $hora = date('H:i', $atu); 
    $sql = mysql_query("INSERT INTO teste (id,hora,data) VALUES('','$hora','$data')");
     $msg = 'Agenda Aberta do dia '  .$data_cadastro.  ' com Successo<br/>';          
    } 
    }

 ?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>agenda</title>

  </head>

  <body>

  <form action="agenda.php" method="post">

  data:<input type="date" name="data">

  <input type="submit" name="submit"  value="agendar">
   </body>

  </html>
    
asked by anonymous 30.07.2017 / 02:11

1 answer

0

Your $data = str_replace($_POST['data']); has the wrong syntax.

Syntax:

str_replace("Este","Por Este","Neste");

str_replace($este,$porEste,$neste);

example: str_replace("correta","errada","a sintaxe está correta");

result a sintaxe está errada

manual - str_replace

My understanding of your code

You are wanting to record 4 records with a 15 minute interval for a certain date. Here is better-formatted code with no str_replace in $_POST['data'] . If there is any replace on the date do it as above!

<?php
include "conexion.php";

if(isset($_POST['submit'])) { 

   $data = ($_POST['data']); 

   $data_cadastro = $data;  

   $hora_inicio = "07:45:00";
   $hora_final = "09:00:00";   
   $ini = strtotime($hora_inicio); 
   $fim = strtotime($hora_final); 

    $atu = $ini;
    $i = 0;
    for ($atu = $ini; $atu < $fim; $atu = strtotime('+15 minutes', $atu)) { 
        $hora = date('H:i', $atu); 
        $sql = mysql_query("INSERT INTO teste (id,hora,data) VALUES('','$hora','$data')");
        $msg = 'Agenda Aberta do dia '  .$data_cadastro.  ' com Successo<br/>';                                                    
    } 
}
echo $msg;
?>
    
30.07.2017 / 04:59