How to capture from session and match database
How to capture from session and match database
am 19.09.2007 05:03:45 von Chris Carter
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 $userName, meaning the userName is 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
--
View this message in context: http://www.nabble.com/How-to-capture-from-session-and-match- database-tf4478519.html#a12770056
Sent from the Php - Database mailing list archive at Nabble.com.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: How to capture from session and match database
am 19.09.2007 15:34:30 von Naintara
Hi,
First of all, where you are storing the session variable, it should be
specified as:
$_SESSION['email'] = 'email value' //PHP 4.1.0 onwards
This is preferred to registering global variables. There's a whole lot of
discussion on why.
On the pages you are authenticating, you would correspondingly check for a
value in $_SESSION['email']
!empty($_SESSION['email']) isset($_SESSION['email']) etc, depending on you.
When you code for the session logout, you need to look up the php manual
for session_destroy().
When you would like to retrieve data for a user, you can get the details by
using code like this:
$query="SELECT * FROM table WHERE email = '".
mysql_real_escape_string($_SESSION['email']). "'";
I would suggest you read up a good tutorial on php + mysql
I am not sure why there are curly braces after mysql_close(); or where you
are setting values to $i
mysql_close();
{
$shopname=mysql_result($result,$i,"shopname");
$category=mysql_result($result,$i,"category");
}
The best thing would be to first understand sessions, set variables, echo
values, destroy variables, and then test the sql.
-----Original Message-----
From: Chris Carter [mailto:chandan9sharma@yahoo.com]
Sent: Wednesday, September 19, 2007 8:34 AM
To: php-db@lists.php.net
Subject: [PHP-DB] How to capture from session and match database
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 $userName, meaning the userName is 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
--
View this message in context:
http://www.nabble.com/How-to-capture-from-session-and-match- database-tf4478
519.html#a12770056
Sent from the Php - Database mailing list archive at Nabble.com.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: How to capture from session and match database
am 23.09.2007 18:28:41 von Chris Carter
Hi Naintara,
thanks for your code could you please advice why is the code giving this
error.
"Parse error: syntax error, unexpected T_ISSET in
/path/submit-store-details.php on line 4"
This is coming when I am trying to use your code like this:
session_start();
$_SESSION['email'] = 'emailAddress';
if(!empty($_SESSION["email"]) isset ($_SESSION["email"]));
{
header("location:store-login.php");
}
?>
and then retrieving it in SQL query:
$query="SELECT * FROM table WHERE email =
'".mysql_real_escape_string($_SESSION['email'])."'";
Many thanks.
Chris
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 $userName, meaning the userName is 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
>
Quoted from:
http://www.nabble.com/How-to-capture-from-session-and-match- database-tf4478519.html#a12770056
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 $userName, meaning the userName is 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
>
--
View this message in context: http://www.nabble.com/How-to-capture-from-session-and-match- database-tf4478519.html#a12847962
Sent from the Php - Database mailing list archive at Nabble.com.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: How to capture from session and match database
am 23.09.2007 19:03:39 von Naintara
Hi Chris,
What I had sent earlier were some hints, references and some code.
I had recommended reading up on sessions, because it's good to know and
useful to get a handle on it, you'll be able to do these things easily
then.
If you are pressed for time and unable to do so, here is some code you
could use
Do read my comments after // (slashes)
session_start();
$_SESSION['email'] = 'php-db@lists.php.net';
//put a real email address here to test with, later remove it and use the
login email id
if( empty($_SESSION["email"]) ) {
header("location:store-login.php");
}
//the above checks if you have a value in your email session variable.
?>
Naintara
-----Original Message-----
From: Chris Carter [mailto:chandan9sharma@yahoo.com]
Sent: Sunday, September 23, 2007 9:59 PM
To: php-db@lists.php.net
Subject: Re: [PHP-DB] How to capture from session and match database
Hi Naintara,
thanks for your code could you please advice why is the code giving this
error.
"Parse error: syntax error, unexpected T_ISSET in
/path/submit-store-details.php on line 4"
This is coming when I am trying to use your code like this:
session_start();
$_SESSION['email'] = 'emailAddress';
if(!empty($_SESSION["email"]) isset ($_SESSION["email"]));
{
header("location:store-login.php");
}
?>
and then retrieving it in SQL query:
$query="SELECT * FROM table WHERE email =
'".mysql_real_escape_string($_SESSION['email'])."'";
Many thanks.
Chris
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 $userName, meaning the userName is 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
>
Quoted from:
http://www.nabble.com/How-to-capture-from-session-and-match- database-tf4478
519.html#a12770056
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 $userName, meaning the userName is 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
>
--
View this message in context:
http://www.nabble.com/How-to-capture-from-session-and-match- database-tf4478
519.html#a12847962
Sent from the Php - Database mailing list archive at Nabble.com.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php