Page 1 of 1

Syntax to use COOKIE id to update DB field

Posted: Wed Sep 29, 2004 3:43 pm
by cdickson
What is the correct syntax to use a cookie for updating a db field?

I have tried:

Code: Select all

$query = "INSERT INTO orders (userid, date) 
VALUES ('{$_COOKIE['userid']}', '$date')";
In place of '{$_COOKIE['userid']}' I have also tried
  • '$_COOKIE['userid']'
    '$userid'
    '{$_POST['userid']}'
without success.

Nothing about this particular syntax came up when I searched PHP.net, Google, etc.

Before posting this question I also confirmed that the cookie is being properly sent by overriding automatic cookie handling in my browser so that I could SEE the cookie.

I think I am close with my syntax, so any help will be truly appreciated.

Posted: Wed Sep 29, 2004 4:14 pm
by Joe
Try:

Code: Select all

$HTTP_COOKIE_VARSї'userid'];

Posted: Wed Sep 29, 2004 4:16 pm
by John Cartwright

Code: Select all

<?php
$query = "INSERT INTO `orders` SET (`userid`, `date`) 
VALUES ('".$_COOKIE['userid']."', '$date')";
?>

Posted: Wed Sep 29, 2004 4:20 pm
by Joe
Well whoops I missed the users query. my way would go like:

Code: Select all

<?php
$query = "INSERT INTO `orders` SET (`userid`, `date`) VALUES ('".$HTTP_COOKIE_VARS['userid']."', '$date')";
?>

Posted: Wed Sep 29, 2004 4:33 pm
by cdickson
Joe - Thanks!

Phenom - You did it again!

You guys are fantastic - I hope I know as much as you do some day.

Posted: Wed Sep 29, 2004 4:36 pm
by John Cartwright
Glad to help :lol: