的解决方案
我用POST方法在一个表单中发送了一个var类型的DATETIME,日期的格式是"2014-04-20 05:00:47",但当boleta.php收到时,它只显示"2014-04-2020"。我不明白,我发布了代码php.html和boleta.php 的代码
代码html/php:
<?php $var=array(); ?> <?php foreach ($model as $data): ?> <h1> <?php $var[]= $data->fecha_ingreso; ?></h1> <?php endforeach?> <form action="boleta.php" method="POST" class="form-horizontal" role="form"> <label for="fecha">Select date</label><br> <select name="fecha" class="form-control"> <option value = <?php echo $var[0]; ?> > <?php echo $var[0];?> </option> <option value = <?php echo $var[1]; ?> > <?php echo $var[1];?> </option> <option value = <?php echo $var[2]; ?> > <?php echo $var[2];?> </option> </select> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="pull-right"> <button type="submit" class="btn btn-primary">Send</button> </div> </div> </div> </form>
code boleta.php
<?php date_default_timezone_set("America/Santiago"); echo $_POST['fecha']; ?>
尝试将您的选项值设置为"from…
<option value = <?php echo $var[0]; ?> >
至
<option value = "<?php echo $var[0]; ?>" >
也许这就是
如果日期时间数组构建正确。你只需要添加"两边的选项值赋值变量,就像这个<option value = "<?php echo $var[0]; ?>" >
。我已经测试了这个示例html,对我有用。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<form action="boleta.php" method="POST" class="form-horizontal" role="form">
<label for="fecha">Select date</label><br>
<select name="fecha" class="form-control">
<option value='2014-04-20 05:00:47'>'2014-04-20 05:00:47'</option>
<option value='2014-04-21 05:00:47'>2014-04-21 05:00:47</option>
<option value='2014-04-22 05:00:47'>2014-04-22 05:00:47</option>
</select>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="pull-right">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</form>
</body>
</html>
希望它能帮助你。