-1

I have an array of data saved in cookie, like this

1:good,2:accelent,3:bad,4:good,fname:Ahmad,lname:Riaz,title:Developer,org:Magiclamp,email:Riaz@khan.com

here i want to save this data in different tables This in one table

1:good,2:accelent,3:bad,4:good

and this in another table

fname:Ahmad,lname:Riaz,title:Developer,org:Magiclamp,email:Riaz@khan.com

how can i solve this problem

Sirko
  • 72,589
  • 19
  • 149
  • 183
  • Question is already asked http://stackoverflow.com/questions/10598201/insert-cookies-data-into-mysql-databas-inphp – ScarCode May 16 '12 at 10:27

2 Answers2

0

Read the cookie using $_COOKIE: $cookie_val = $_COOKIE['NAME'];

Split the input using explode(): $cookie_array = explode(",", $cookie_val);

From the result array use the values needed: $cookie_array[0], $cookie_array[1] ...

Clean the values before insertion into the db.

Adam
  • 1,684
  • 14
  • 18
0
<?php
$str = "1:good,2:accelent,3:bad,4:good,fname:Ahmad,lname:Riaz,title:Developer,org:Magiclamp,email:Riaz@khan.com";

$rows = explode(',', $str);

$data['table1'] = $data['table2'] = array();

foreach($rows as $k => $v) {
$a = explode(':', $v);
$data[(is_numeric($a[0]) ? 'table1' : 'table2')][$a[0]] = $a[1];
}

var_dump($data);
?>

That will split the data into two arrays.

Gustav Westling
  • 633
  • 3
  • 9