-2

I'm trying to get the format of Date/Time from the URL with the $_GET and put it into a input field:

This is the format: 09/11/2019 14:48 CDT 09/11/2019 14:48 CDT

$stime = "09/11/2019 14:48 CDT 09/11/2019 14:48 CDT";
$etime = "";

This is part of the code when the form is submitted:

includes/connect.inc.php

    if (empty($stime) || empty($etime)) {
            header("Location: ../home.php?error=emptyfields&stime=".rawurlencode($stime)."");
            exit();
}

This is the code where the form/input fields are:

home.php

if (isset($_GET['error'])) {

    $stime = ($_GET['stime']);

}else {

    $stime = "";

}


<form method="post" action="includes/connect.inc.php" enctype="multipart/form-data">
<li>Start Time : <input type="text" name="stime" id="dato8" value=<?php echo rawurldecode($stime); ?> ></li>
<input type="submit" value="Submit" class="button">
</form>

All works fine but the string that returns to the input field is just: "09/11/2019", missing the rest of the original string.

Any idea of what am i doing wrong?

I did a test in a separate file with this code:

<?php

$dateDecoded = "09%2F11%2F2019%2014%3A48%20CDT%2009%2F11%2F2019%2014%3A48%20CDT";
$dateToEncode = "09/11/2019 14:48 CDT 09/11/2019 14:48 CDT";
echo rawurldecode($dateDecoded);
echo "<br>";
echo rawurlencode(dateToEncode);

 ?>

And works perfect, does the result i'm looking for, this is the output of the above test:

09/11/2019 14:48 CDT 09/11/2019 14:48 CDT
09%2F11%2F2019%2014%3A48%20CDT%2009%2F11%2F2019%2014%3A48%20CDT

Thanks in advance.

Diego

  • your if condition in **includes/connect.inc.php** should be inverted: `if (empty($stime) || empty($etime)) {` should be `if (!empty($stime) || !empty($etime)) {` – admcfajn Jan 15 '20 at 05:52
  • _“Any idea of what am i doing wrong?”_ - you neglected to properly enclose the attribute value in quotes … – 04FS Jan 15 '20 at 08:33
  • Hi @04FS thank yo u for your time, could you be more specific please? – Diego Duarte Jan 15 '20 at 16:48
  • @04FS oh i got it, you are right, i forgot to do that, please write you comment as an answer, thank you for your time and help, have a great day. – Diego Duarte Jan 15 '20 at 16:58

1 Answers1

0

I forgot to add the double quotes, the code should be like this:

<li>Start Time : <input type="text" name="stime" id="dato8" value="<?php echo rawurldecode($stime); ?>"></li>

Thank you all.