0

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");
    }
    }
3
Contributors
10
Replies
52
Views
1 Year
Discussion Span
Last Post by cereal
Featured Replies
0

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.

Edited by zebnoon1

0

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

0

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

0

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]);
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.