Save my cookie data to MySQL database?(将我的 cookie 数据保存到 MySQL 数据库?)
问题描述
我在做一项调查,我是离线服务器,所以我将用户信息保存在 cookie 中,我有这样的用户信息
I was doing a survey I was offline server so I save users information in cookies, I have users Information like this
Fname:Ali,Lname:Kheiri,title:Director,org:Magiclamp,email:alikheiri@gmail.comFname:Ali,Lname:Kheiri,title:Director,org:Magiclamp,email:alikheiri@gmail.com
它保存在cookies中,但现在我在线,所以我想将此cookies数据保存在php中的mysql数据库中,为此我编写了javascript代码,但它不起作用
it is save in cookies, but now i am online, so i want to save this cookies data in mysql database in php, javascript for this I write this code but its not working
mysql_connect("localhost","root","");//database connection05
mysql_select_db("o2measure");
if($_POST['submit']){
$date = date('Y,m,d');
$time = date("i:h:s",time() + $time_a);
echo $session_id;
$ip=$_SERVER['REMOTE_ADDR'];
foreach($_COOKIE as $name => $cookie){
// you can check any conditions based on cookie name $name
$sql="INSERT INTO user_data (first_name, last_name, job_title, organisation, email, phone_number, ip_address, date, time)
VALUES(" . mysql_escape_string($cookie) . ")";
$result=mysql_query($sql);
}
推荐答案
你应该将 cookie 值作为一个字符串拆分它并单独使用每个条件而不是使用插入查询,因为你写的查询不正确你说插入 user_data名字 姓氏 职位名称...但您只给他 1 个值 $cookie 但 sql 不知道 $cookie 包含所有内容,因此您应该首先根据 ',' slpit cookie 值
you should get the cookie value as a string split it and have every criteria alone than use the insert query because the query you wrote is incorrect you saying insert into user_data the first name the last name the job title... but you are only giving him 1 value the $cookie but the sql don't know that the $cookie contain everything so you should first slpit the cookie value based on the ','
这篇关于将我的 cookie 数据保存到 MySQL 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将我的 cookie 数据保存到 MySQL 数据库?


- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01