Form input field truncates time stamp

Hello,
I want to to make it possible for users to edit data stores in DB.

When data is extracted from the DB it is displayed in form input fields, where ic can be edited
Here is the code for insertind the extracted data into input fields:

<?php foreach ($positions as $pkey=>$pval)
				              {
				               echo '<tr>
										<td><input type="text" name-"id[]" value ='.$pval['id'].'></td>
										<td><input type="text" name-"ticket[]" value ='.$pval['ticket'].'></td>
										<td><input type="text" name-"o_time[]" value ='.$pval['o_time'].'></td>
										<td><input type="text" name-"type[]" value ='.$pval['type'].'></td>
										<td><input type="text" name-"size[]" value ='.$pval['size'].'></td>
										<td><input type="text" name-"item[]" value ='.$pval['item'].'></td>
										<td><input type="text" name-"o_price[]" value ='.$pval['o_price'].'></td>
										<td><input type="text" name-"s_l[]" value ='.$pval['s_l'].'></td>
										<td><input type="text" name-"t_p[]" value ='.$pval['t_p'].'></td>
										<td><input type="text" name-"c_time[]" value ='.$pval['c_time'].'></td>
										<td><input type="text" name-"c_price[]" value ='.$pval['c_price'].'></td>
										<td><input type="text" name-"profit[]" value ='.$pval['profit'].'></td>
										<td><input type="checkbox" name="update[]"></td>
										<td><input type="checkbox" name="delete[]"></td>
									</tr>';
						      }
			?>

In this code configuration , o_time looks like this: 2017-07-31
The time of the timestamp disappears

When I change the table cell code to
<td>'.$pval['o_time'].'</td>
the input value is 2017-07-31 08:24:11

Why does it happen?
How do I ensure that the value in the input field will be a timestamp ?

Is this your actual code? Does not make much sense unless you are using a very strange templating system. And I don’t just mean the timestamp either.

name-"id[]" ???  
value ='.$pval['id'].' ?????

I think you are trying some huge concatenated string thing. Your values don’t have double quotes around them. Which eventually is messing things up.

Maybe try the heredoc syntax:

$html = <<<EOT
<tr>
  <td><input type="text" name="id[]" value="{$pval['id']}"></td>
EOT;
echo $html;

And don’t forget to html escape your output values. Any special html characters in your data will also mess things up.

Are these bits

name-"id[]"

and the rest typos in the forum post? Shouldn’t that read

name="id[]"

If you’re just listing all columns in a row you’ve retrieved from a query, I think I’d be tempted to have another loop:

<?php foreach ($positions as $pkey=>$pval) {
  echo '<tr>';
  foreach ($pval as $ix=>$val) { 
    echo '<td><input type="text" name="' . $ix . '[]" value ="'.$val .'"></td>';
    }
  echo '<td><input type="checkbox" name="update[]"></td>';
  echo '<td><input type="checkbox" name="delete[]"></td>';
  echo '</tr>';
}						      }
?>

No idea why it truncates the timestamp though.

Rather than using single quotes that you have to keep opening and closing, you would be better off using Heredoc syntax which will make your code a lot easier to read.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.