I’m trying to access each value in a array without serializing it.
I than want this data stored into a datetime field in MySQL.
The data is received from my form [collect] => Array ( [0] => 01 [1] => 06 [2] => 2011 [3] => 17 [4] => 41 )
How can i store this array data into my database ‘datetime’ field column?
$dd=$_POST('$collect[0]');
$mm=$_POST('$collect[1]');
$yy=$_POST('$collect[2]');
$hh=$_POST('$collect[3]');
$ii=$_POST('$collect[4]');
$ddate = ('$yy','$mm','$dd',NULL,'$hh','$ii',NULL)
What i’m trying to do above is take each array value and store it in variable names and than use variable $ddate to store as a datetime in my database. I’m not sure if this is even possible, but i have tried serialize, but date will not insert into database just shows format 0000/00/00 00:00 on database so i’m trying the above to see if this can work.
If there’s a universal way I can use instead of the above, please can someone show me a small example which I can work from.
From what you wrote, I’m assuming that the form field is called
collect[]seeing you’re trying to access its indexes.However, you’re using wrong method here –
$_POSTis an array, yet you tried to use it as a function (not that it’s impossible, but for this purpose – it’s really not the way to do it).And so on until you reach the last element of your array.
If you are storing some user-submitted date to the MySQL – yes, there are better ways to do it. If you wish to know what they are, feel free to comment so I’ll post my views on what better ways exist.