Dear Friends,
I ctreate database in mysql database data transfer from PHP form.
Problem: I can not save my Date formate(dd-mm-yy) in to database.
My code is below please,

if($epr=='save'){
     // $cid=$_POST['id'];
    $edate=$_POST['edate'];
    //$edate=date("d-m-y h:i:s a",time());
    $ldate=$_POST['ldate'];
    //$ldate=date("d-m-y h:i:s a");
    $cdetail=$_POST['cdetail'];
    $tdetail=$_POST['tdetail'];
        $sql1="INSERT INTO tentb(edate,ldate,cdetail,tdetail) VALUES('$edate','$ldate','$cdetail','$tdetail')";
        $result1=$conn1->query($sql1);
    if($result1){
    echo "Data has saved";
    header("refresh:2; url=tenderadd.php");}
    else{
        $msg='Error'. $conn1->connect_error;
        header("refresh:2; url=tenderadd.php");
    }
    }

any body can help me please,

dear pritaeas,
we can not use "dd-mm-yyyy" OR "dd NmeOfMonth YYYY "in php form? and how to convert format to send as a mysql format date.

yes i am using datepickep code is below

<script>
        $(document).ready(function(){
        $("#date").datepicker({
            dateFormat:"dd-mm-yy"
        });

        });
         </script>

but when i transfer date in database shows 0000-00-00 00:00:00

thaks for response ,
sir, cn you give any example. in insert query with DATE().

Example:

$sql = "INSERT INTO `tentb` (`edate`) VALUES(DATE($edate))";

But you should be using prepared statements, so:

$sql = $db->prepare("INSERT INTO `tentb` (`edate`) VALUES(DATE(:edate))");
$sql->execute([':edate' => $edate]);

thx Cereal,
i check this quiry but I got error please, check

$edate=$_POST['edate'];

    $ldate=$_POST['ldate'];
    $cdetail=$_POST['cdetail'];
    $tdetail=$_POST['tdetail'];
        $sql1 =$conn1->prepare ("INSERT INTO `tentb` (`edate`) VALUES(DATE(:edate))");
        $sql1->execute([':edate'=>$edate]);

        $result1=$conn1->query($sql1);
    if($result1){
    echo "Data has saved";
    header("refresh:2; url=tenderadd.php");}
    else{
        $msg='Error'. $conn1->connect_error;
        header("refresh:2; url=tenderadd.php");
    }

Error: Call to a member function execute() on a non-object in C:\wamp\www\SprintWeb\tenderadd.php on line 26

Is $conn1 a PDO or a MySQLi resource? It connects to the database correctly? Follow the documentation of the chosen library to properly work with prepared statements. If you just want to verify if the DATE() works fine for you, then use the first example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.