Novice_2011
Novice_2011

Reputation: 29

posting array to MySQL

How can insert a array into my MySQL database?

I have managed to insert some of this data into the database already.

Below is part of my code:

$depart=serialize($_POST['departure']); 
$sql="INSERT INTO bookings VALUES('$depart');

I am trying to insert

[departure] => Array ( [0] => 30 [1] => 05 [2] => 2011 [3] => 17 [4] => 41 )

into the database field 'depart'

your help will be much appreciated.

Upvotes: 0

Views: 188

Answers (2)

Emil Ahlbäck
Emil Ahlbäck

Reputation: 6206

You should escape your serialized array string.

$depart=mysql_real_secape_string(serialize($_POST['departure']));

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116100

Assuming 'depart' is a datetime field:

$timestamp = mktime($depart[3], $depart[4], 0, $depart[2], $depart[1], $depart[0]);

$sql = "insert into bookings(depart) values (from_unixtime($timestamp))";

// Execute the sql as normal

Upvotes: 1

Related Questions