問題描述
我在做一項調查,我是離線服務器,所以我將用戶信息保存在 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 數據庫?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!