本文介绍了无法将日期存储到PHP中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>  
<html>  
<head>  
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/  
jquery-ui.css" rel="stylesheet" type="text/css"/>  
<script type="text/javascript"   
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>  
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">  
</script>  

<script>
$(document).ready(function() {
$(".datepicker").datepicker()
});
</script>
</head>
<body>
<?php
$status = $_POST['status'];  
$driver_name= $_POST['driver_name'];  
$from=date('y-m-d',strtotime($_POST['date_from']));  
$to=date('y-m-d',strtotime($_POST['date_to']));  
$conn = mysqli_connect('localhost', 'root', '', 'punbus') or  
    die("Database not connected" . mysqli_error());
if(isset($_POST['sub'])) {
foreach($status as $k=>$s){
    $ins = "insert into driver_status(driver_name,status,date_from,date_to) 
VALUES                   
        ('".$driver_name[$k]."','$s','".$from[$k]."','".$to[$k]."')";
        $quer=mysqli_query($conn,$ins);
        }
    if($quer){
        echo "Updated";
    }else{
        echo"NOT".mysqli_error($conn);
    }
 }

$sel = 'select Driver_name from driver_master';
$query = mysqli_query($conn, $sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){    
 echo "<tr><td>".$row['Driver_name']
       ."<input type=\"hidden\" name=\"driver_name[]\"
 value=\"".$row['Driver_name']."\"/></td>";
 $sel1='select d_status from status';
 $query1=mysqli_query($conn,$sel1);
 echo "<td><select name=\"status[]\">";
 while($row1=mysqli_fetch_assoc($query1)){
       echo "<option value=\"".$row1['d_status']."\">".$row1['d_status']."  
 </option>";
 }
 echo "</select></td>";
 echo "<td>".'<input type="text" name="date_from[]" class="datepicker">'."</td>";
 echo "<td>".'<input type="text" name="date_to[]" class="datepicker">'."</td>";
 echo "</tr>";
 }
 echo "</table>";
 echo '<input type="submit" name="sub" value="Update"/>';
 echo "</form>";
 ?>
 </body>
 </html>

我想从jquery datepicker将日期存储到数据库.上面是我的代码,错误是警告:strtotime()期望参数1为字符串,给定数组.我可以将日期作为array.Plz帮助存储到数据库中吗?

I want to store date to database from jquery datepicker. above is my code and error is Warning: strtotime() expects parameter 1 to be string, array given. Can i store date to database as array.Plz help.

推荐答案

将输入名称更改为:-

echo "<td>".'<input type="text" name="date_from" class="datepicker">'."</td>"; //  remove []
echo "<td>".'<input type="text" name="date_to" class="datepicker">'."</td>"; //  remove []

像这样使用Dateformat

Use Dateformat like this

Try: date("Y-m-d") which uses the numeric equivalents.

这篇关于无法将日期存储到PHP中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:23