我在数据库中输入0000-00-00
的日期是dd-mm-yyyy
格式,我也应该怎么做才能以dd-mm-yyyy
格式获取SQL?
这是我的代码,我在https://youtu.be/r_JW1PDZlZo上观看了YouTube视频,做了日期格式化部分
我试图将其与已经完成的代码合并
我是PHP的新手,不知道如何更改它们,请以一种简单的方式逐步重播
<html>
<head>
<h4 style="color:green;">ADD YOUR DETAILS BELOW </h4>
<script src="https://kit.fontawesome.com/d3d5464d46.js" crossorigin="anonymous"></script>
<script type="text/javascript">
$(function() {
$("#datepicker").datepicker({
dateFormat: "dd-mm-yy"
}).val()
});
</script>
<body style="background: url(img/too.jpg); background-repeat;background-size:100% 100%">
<a href="index.php">
<button <i class="fas fa-home"></i> RETURN</button>
</a>
<br></br>
<br></br>
<form action="add.php" method="post" name="form1">
<table>
<link rel="stylesheet" type="text/css" href="style.php?" />
<tr>
<td>Company Name</td>
<td>
<input type="text" name="company_name" placeholder="companie's name..">
</td>
</tr>
<tr>
<td>Client Name </td>
<td>
<input type="text" name="client_name" placeholder="your's name..">
</td>
</tr>
<tr>
<td>Date of entry</td>
<td>
<input type="date" name="date_of_entry" placeholder="DD/MM/YYYY">
</td>
</tr>
<tr>
<td>Phone</td>
<td>
<input type="text" name="phone" placeholder="phone no">
</td>
</tr>
<p>
<tr>
<td></td>
<td>
<button type="submit" name="submit" value="ADD" <i class="fas fa-plus">
</i> ADD</button>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$comp_nam =$_POST['company_name'];
$cli_nam =$_POST['client_name'];
$dat=$_POST['date_of_entry'];
$phn=$_POST['phone'];
$resulto= explode('-','/' $dat);
$date=$resulto[2];
$month=$resulto[1];
$year=$resulto[0];
echo $dat=$date.'-'.$month.'-'.$year;
include_once"config.php";
$result= mysqli_query($conn,"INSERT INTO information (company_name,client_name,date_of_entry,phone) VALUES('$comp_nam','$cli_nam','$dat','$phn')") or die(mysqli_error($conn));
header("location:index.php");
echo "User added successfully";
}
?>
</body>
</html>
请有人尽快回答我
答案 0 :(得分:0)
此
echo $ dat = $ date .'-'。$ month .'-'。$ year;
应该是
echo $ dat = $ year .'-'。$ month .'-'。$ date;