not inserteing date in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kalpesh
Forum Commoner
Posts: 54
Joined: Sun Sep 21, 2008 5:04 am

not inserteing date in mysql

Post by kalpesh »

Hi,
I try to insert data in mysql from php.
I insert all data except field Date_Inserted where i store current date.
And It is inserting '0000-00-00'.

My code is as below:

Code: Select all

 
$db->startTransaction();
        try{
             $today1 =date("Y-m-d");
            $arValues = array();
 
                                    $arValues['Pro'] = $pid;
                                    $arValues['Cat'] = $proidhist['Cat];
                                    $arValues['Sub']=$proidhist['Sub'];
                                    $arValues['StartDate']=$proidhist['StartDate'];
                                    $arValues['EndDate']=$proidhist['EndDate'];             
                                    $arvalues['Date_Inserted']=$today1;
                                    $newId=$db->insertdelay("history",$arValues);
                                    $Result = "Product Information updated successfully.<br>\n";
                                    $db->commit();
                                }
                                catch(Exception $e)
                                {
                                    $db->abort();
                                    print "an error Ocurred.<br>\n".$e->getMessage();
                                    $Result = "Product Information updated couldn't take place.";
                                }
 
 
please help me
Thanks in advance.
Last edited by Benjamin on Sat May 16, 2009 10:00 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: not inserteing date in mysql

Post by Benjamin »

Look at what the syntax highlighting uncovered :)

:arrow: Moved to PHP - Code
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: not inserteing date in mysql

Post by ldougherty »

Not sure if this will fix the problem of inserting the correct date but your line

Code: Select all

$arValues['Cat'] = $proidhist['Cat];
needs to be changed to

Code: Select all

$arValues['Cat'] = $proidhist['Cat'];
as it is missing the end ' after Cat
Last edited by Benjamin on Sat May 16, 2009 12:36 pm, edited 1 time in total.
Reason: Changed code type from text to php.
kalpesh
Forum Commoner
Posts: 54
Joined: Sun Sep 21, 2008 5:04 am

Re: not inserteing date in mysql

Post by kalpesh »

Code: Select all

 
 $db->startTransaction();
         try{
             $today1 =date("Y-m-d");
            $arValues = array();
 
                                     $arValues['Pro'] = $pid;
                                     $arValues['Cat'] = $proidhist['Cat'];
                                   $arValues['Sub']=$proidhist['Sub'];
                                     $arValues['StartDate']=$proidhist['StartDate'];
                                    $arValues['EndDate']=$proidhist['EndDate'];            
                                    $arvalues['Date_Inserted']=$today1;
                                   $newId=$db->insertdelay("history",$arValues);
                                     $Result = "Product Information updated successfully.<br>\n";
                                    $db->commit();
                                }
                                catch(Exception $e)
                               {
                                    $db->abort();
                                    print "an error Ocurred.<br>\n".$e->getMessage();
                                    $Result = "Product Information updated couldn't take place.";
                                }
  
 
I edit the code but it still not insert date in database.
it is still inserting '0000-00-00'
When i try the code in other pages where i insert in other tables, there it is working perfectly fine.
It is only in that table where i could not insert the date.
But when i try to insert value with mysql_query then it works but it is not working with this code.
Post Reply