把数据保存到cook_将我的Cookie数据保存到MySQL数据库?

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.com

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

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);

}

解决方案

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 ','

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值