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
kalpesh
Forum Commoner
Posts: 54 Joined: Sun Sep 21, 2008 5:04 am
Post
by kalpesh » Sat May 16, 2009 3:31 am
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.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sat May 16, 2009 10:02 am
Look at what the syntax highlighting uncovered
Moved to PHP - Code
ldougherty
Forum Contributor
Posts: 103 Joined: Sun May 03, 2009 11:39 am
Post
by ldougherty » Sat May 16, 2009 12:09 pm
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
Post
by kalpesh » Sat May 16, 2009 11:45 pm
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.