-5

Possible Duplicate:
Save my cookie data to MySQL database?

I want save data into mysql **database**** from **cookies in php. I have an application that store data in cookies at offline server, I want to save this cookies in my sql database when I go online.

Community
  • 1
  • 1
  • I'm flagging as a dup [of this](http://stackoverflow.com/questions/10550441/save-my-cookie-data-to-mysql-database). – halfer May 15 '12 at 10:31

1 Answers1

-2

Your question is not clear, but it may be useful to you.

You can iterate over php cookie array and insert it in your table.

foreach($_COOKIE as $name => $cookie){
    // you can check any conditions based on cookie name $name
    $query1 = "INSERT INTO table_name(field_name) VALUES(" . mysql_escape_string($cookie) . ")";
    mysql_query($query1);
    unset($query1);
}
Sanjay
  • 1,570
  • 1
  • 13
  • 30
  • 1
    Please stop writing new code with the ancient `mysql_*` functions. They are no longer maintained and community has begun the [deprecation process](http://goo.gl/KJveJ) . Instead you should learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you cannot decide, [this article](http://goo.gl/3gqF9) will help to choose. If you care to learn, [here is a quite good PDO-related tutorial](http://goo.gl/vFWnC). – vascowhite May 11 '12 at 07:20
  • @vascowhite, Thanks for your comment but it was just an example to show a way. It is not good idea to explain the answer with PDO or ORM or anything else involved for the simple questions. – Sanjay May 11 '12 at 07:25
  • 1
    How is showing the correct way not a good idea? Using mysql_* functions is wrong, you shouldn't be telling people to use them. If you bother to learn about PDO you'll see it is quite simple, certainly no more complex than mysql_* functions. See this answer on [PDO](http://stackoverflow.com/a/60496/212940) – vascowhite May 11 '12 at 07:26