Dynamic Cookies Names with MySQL Queries.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pongles
Forum Newbie
Posts: 2
Joined: Sat Aug 09, 2003 5:09 am
Location: At a Computer
Contact:

Dynamic Cookies Names with MySQL Queries.

Post by Pongles »

Hi, I've designed a dynamic moduler based PHP script, but I am having a problem with using dynamic cookies.

Well, what do I mean by a dynamic cookie?

Well the cookie name is dependant on what the site title is, which is looked up in a MySQL table and stored in $config_site, which is easy to understand.

To compare the infomation sent by a from (e.g when logging on) with a user within a database is quite straight-forward.

Code: Select all

$login_link = mysql_query("SELECT * FROM `$mysql_user` WHERE 1 AND `username` = '$_POSTїusername]' AND `password` = '$_POSTїpassword]' LIMIT 0, 1",$db);
However, I am having trouble with the syntax when when checking if a user is logged on, take a look ->

Code: Select all

$user_link = mysql_query("SELECT * FROM `$mysql_user` WHERE 1 AND `username` = '$_COOKIEї$config_title.'їusername]']' AND `password` = '$_COOKIEї$config_title.'їpassword]']' LIMIT 0, 1",$db);
Now I know I can't use this because it'll attempt to close the quotes when it reaches itle.'[use[.
So I looked in the MySQL manual and you can use double quotes to indicate the start of a new quote opening like this ->

Code: Select all

$user_link = mysql_query("SELECT * FROM `$mysql_user` WHERE 1 AND `username` = '$_COOKIEї$config_title.''їusername]'']' AND `password` = '$_COOKIEї$config_title.''їpassword]'']' LIMIT 0, 1",$db);
However, you can't do that with PHP because of the way it parses strings.

I know I'm doing something wrong, can anyone help?
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Why dont you try just making it a variable, right above that put:

Code: Select all

<?php
$cookieuser = $_COOKIE[$config_title.'[username]'];
$cookiepass = $_COOKIE[$config_title.'[password]'];
?>
Then in the query just do:

Code: Select all

<?php
$user_link = mysql_query("SELECT * FROM `$mysql_user` WHERE 1 AND `username` = '$cookieuser' AND `password` = '$cookiepass' LIMIT 0, 1",$db); 
?>
Pongles
Forum Newbie
Posts: 2
Joined: Sat Aug 09, 2003 5:09 am
Location: At a Computer
Contact:

Post by Pongles »

well, I thought about that but it makes untidy code, o well, I 'll have to use up *more* memory/CPU time.
Post Reply