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);
}
您应该将cookie值作为字符串进行拆分,并使用插入查询来单独处理所有条件,因为您编写的查询不正确,是说您将user_data中的名字插入姓氏中,将职位名称姓氏...但是您只给出了他为1设置了$ cookie的值,但是sql不知道$ cookie包含所有内容,因此您应该首先基于','丢弃cookie值
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.