Syntax to use COOKIE id to update DB field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Syntax to use COOKIE id to update DB field

Post 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.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Try:

Code: Select all

$HTTP_COOKIE_VARSї'userid'];
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
$query = "INSERT INTO `orders` SET (`userid`, `date`) 
VALUES ('".$_COOKIE['userid']."', '$date')";
?>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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')";
?>
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Joe - Thanks!

Phenom - You did it again!

You guys are fantastic - I hope I know as much as you do some day.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Glad to help :lol:
Post Reply