inservt database value into date form field - php

I've created a form so I can update a database table. Everything's working (text, file, select, radio) except my date form fields.
Empty, they show the default date placeholder text: mm/dd/yyyy. I can insert a value manually:
<input name="iu_received" type="date" class="form-control" id="iu_received" value="2022-09-20">
And that will show as 09/20/2022 on the page.
However, trying to insert a value from my database recordset doesn't do anything and the placeholder text still displays. For example:
<label class="form-label mb-0">Date Distributed:</label> <input type="date" class="form-control" name="iu_distrib" value="<?php echo $rsAppl->getColumnVal("iu_distrib"); ?>">
(Yes, the "iu_distrib" value is a mysql date: 2022-09-20.)
How can I make this work?

Related

Filling the field of the datum form automatically with the date of today

I am building a web page for an admin dashboard using PHP and I have the following code, for the input date form and what I want is that if the "startdatum" is empty it must fill today's date in automatically.
<input type="date" class="form-control" placeholder="startdatum" id="startdatum" name="startdatum">
Here's how you can do it:
Btw, the <input type="date"> isn't supported on safari.
This example assumes that the input tag will always be empty when showing up, the user can later change the values.
<?php
$a = date("Y-m-d");
?>
<input type="date" id="startdatum" name="startdatum" value="<?php echo $a ?>">

php format field datetime-local in to php

i have this input which i take like this
<input type="datetime-local">
which i am inserting in the db successfully. In the database it stores as such in my table
2021-05-17 23:00:00
but then i am trying to display it in my page like so
<input type="datetime-local" value="<?php echo $date_time; ?>" >
but it gives me a blank field
but when i inspect it shows my the correct value in the value field
get datetime from database using DATE_FORMAT()
SELECT *, DATE_FORMAT(datetime, '%Y-%m-%dT%H:%i') AS custom_date
and after fetching data in which variable your data exist use that in your input value
<input type='datetime-local' name='datetime' value='<?php echo $row['custom_date'] ?>' >

get the data to datetime-local from php

I have a datatype "TIMESTAMP" in database. And I pass the value by using "datetime-local" attribute in html.
<input type="datetime-local" id="start_time" class="form-control" name="start_time"/>
this works fine and i can upload the date and time to database. But when i retrieve the data form database for editing, it doesn't work.
PHP Code
$query="SELECT * FROM hire WHERE hire_id='$id'";
$query_run=mysqli_query($con,$query);
$row=mysqli_fetch_array($query_run);
HTML Code
<input type="datetime-local" value="<?php echo $row['start_time']; ?>" />
The above php within the html shows nothing as a result. What is the fault here?
Because you have the input type set to 'datetime-local'. You have to have the date set to the right format in order for it to show up in the input.
Change your start_time value to be in this format.
$date = date("Y-m-d\TH:i:s", strtotime($row['start_time']));
Then in your input field echo out $date
<input type="datetime-local" value="<?php echo $date; ?>" />
first of all if you should get date from mysql then convert that string to date using strtotime function after that change the format of date and set it at value attribute of input form control haivng type="datetime-local".
$string_to_date=$d=strtotime($date_fromdatabase);
$new_date=Date('Y-m-d\TH:i',$string_to_date);
set as a value attribute of input element in laravel 6
<input type="datetime-local" class="form-control" value="{{ $new_date }}">

cakephp datetime input value not displayed

I've created an input-field for a datetime and I also get the value set, but I've got no value displayed:
HTML:
<input name="data[Date][dat_date_time]" dateformat="DMY" timeformat="24" type="datetime-local" value="2015-08-26 20:23:44" id="DateDatDateTime" required="required">
in Browser:
can anybody help me, why the date and the time is not displayed?
You need to add the letter T before your time:
<input name="data[Date][dat_date_time]" dateformat="DMY" timeformat="24" type="datetime-local" value="2015-08-26T20:23:44" id="DateDatDateTime" required="required">
More information: http://www.w3.org/TR/html-markup/input.datetime-local.html

Overwrite input value in form field

I have an "Update Profile" script that retrieves the details of the logged in user in a form input, so they can see what the current values are. Like this:
<input type="text" name="first_name" id="first_name" value='<?= $row->f_name; ?>' title="enter your first name.">
This works. When users navigate to the page they see their first name appear in that input box. When they go to change their name and enter in a new value the form submits but keeps the original value and not the updated one. I assume that is because I am hard-coding a value to it with the value attribute.
How can I show the user the value in the input so that if they choose to not edit it, it does submit with the original value and not a blank, but if they do choose to add text to the input box the new string is submitted?
If I understand you correctly:
value="<?=set_value('first_name', $first_name)?>"
The first parameter is the posted value, the second parameter is the default overridden value.
You may want to use placeholder attributes.
<input type="text" name="first_name" placeholder="<?= $row->f_name; ?>">
`if($_GET['first_name']==''){
$first_name= $row->f_name;
}else{
$first_name= $_GET['first_name'];
}`
SQL Query :
"UPDATEyour_table_nameSETfirst_name= '$first_name' WHEREblablabla= '$blablalba';"
&ltinput type="text" name="first_name" id="first_name" value='f_name; ?>' title="enter your first name.">

Categories