当前位置: 动力学知识库 > 问答 > 编程问答 >

php - unable to set cookie on form submission

问题描述:

I'm trying to set a cookie on form submission and the form submission handler is running, as I connect to a db inside and that works, but the cookie is not being set.

I've even tried to set a dummy cookie of just a string instead of one of the form values. What am I doing wrong?

<?php

if($_POST['submit'] && $_POST['rememberMe']){

//connect to db

$idNumber=mysql_query("SELECT COUNT(id) FROM users");

if(!$idNumber){ die('Count not get user id: '.mysql_error()); }

setcookie('dummy', 'dummyCookie', time() + 60 * 60 * 24 * 90 );

setcookie('id', $idNumber, time() + 60 * 60 * 24 * 90 );

setcookie('name', $_POST['name'], time() + 60 * 60 * 24 * 90 );

$sqlName = mysql_query("INSERT INTO users SET " .

"name='".$_POST['name']);

$sqlTeam = mysql_query("INSERT INTO users SET " .

"team='".$_POST['faveTeam']);

if(!$sqlName || !$sqlTeam){ die('Count not insert in database: '.mysql_error()); }

}

?>

Does anyone have any ideas?

分享给朋友:
您可能感兴趣的文章:
随机阅读: