将我的Cookie数据保存到MySQL数据库? [英] Save my cookie data to MySQL database?

查看:1209
本文介绍了将我的Cookie数据保存到MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个调查我是离线服务器,所以我保存用户的cookies信息,
我有用户这样的信息

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,标题:Director,org:Magiclamp,电子邮件:alikheiri@gmail.com
名字:Ali,Lname:Kheiri,标题:Director,org:Magiclamp,电子邮件:alikheiri@gmail.com

Fname:Ali,Lname:Kheiri,title:Director,org:Magiclamp,email:alikheiri@gmail.com Fname:Ali,Lname:Kheiri,title:Director,org:Magiclamp,email:alikheiri@gmail.com

它保存在cookies,但现在我在线,所以我想保存这个cookie数据在mysql数据库中php,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基于','

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数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆