Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

php - Save my cookie data to MySQL database?

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:[email protected] Fname:Ali,Lname:Kheiri,title:Director,org:Magiclamp,email:[email protected]

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

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...