For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > September 2007 > Re: [PHP-DB] How to capture from session and match database









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] How to capture from session and match database
Goltsios Theodore

2007-09-19, 6:59 pm


You can use cookies to keep your info so that you don't pass them from
page to page. A way to do this is:
$email = 'test@hostname.domain';
session_start();
setcookie('e-mail',$email);

And then retrieve the cookie information using the $_COOKIE array:

$query="SELECT * FROM table WHERE email = '".$_COOKIE['e-mail']."'";

Every browser keeps information about the cookies that already has
accepted. If this is to work for you then check your browser to see if
the cookie exists and keeps all that you need. A good idea is to erase
the previous cookies accepted from your web server.


Chris Carter wrote:
> Hi,
>
> I have this session code on each page and this is working fine for
> authentication:
>
> <?
> session_start();
> if(!session_is_registered(email)){
> header("location:store-login.php");
> }
> ?>
>
> Now I wish to
>
> 1)capture the value (userName) from session on one of my pages and
> 2)match it with the database and
> 3)display the value in the textfields
>
> This is the code I am using to do this please:
>
> include "../includes/malls_db_conf.php";
>
> $query="SELECT * FROM table WHERE email = '$email'"; <---- Here I am
> capturing from the session
> $result=mysql_query($query);
> $num=mysql_numrows($result);
>
> mysql_close();
> {
>
> $shopname=mysql_result($result,$i,"shopname");
> $category=mysql_result($result,$i,"category");
>
> }
>
> ?>
>
> Showing in the textfield from the database is working fine
>
> THE Problem is:
>
> I am getting only the first row of table to show up and not the one with the
> field $email, meaning the emailis not getting captured from the above or
> checking with the table and showing me the value.
>
> It might be a basic one, could you please advice how to achieve that.
>
> Cheers,
>
> Chris
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com