問題描述
我在做一項(xiàng)調(diào)查,我是離線服務(wù)器,所以我將用戶信息保存在 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中,但現(xiàn)在我在線,所以我想將此cookies數(shù)據(jù)保存在php中的mysql數(shù)據(jù)庫中,為此我編寫了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);
}
推薦答案
你應(yīng)該將 cookie 值作為一個(gè)字符串拆分它并單獨(dú)使用每個(gè)條件而不是使用插入查詢,因?yàn)槟銓懙牟樵儾徽_你說插入 user_data名字 姓氏 職位名稱...但您只給他 1 個(gè)值 $cookie 但 sql 不知道 $cookie 包含所有內(nèi)容,因此您應(yīng)該首先根據(jù) ',' 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 ','
這篇關(guān)于將我的 cookie 數(shù)據(jù)保存到 MySQL 數(shù)據(jù)庫?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!