MySQL Syntax errors
am 08.03.2006 23:11:47 von John Hopper
Hi all
I am currently trying to construct a database-driven membership site. I'm
using Dreamweaver MX 2004, php & MySQL.
All works well, but what I want the member homepage to do is to say 'Hello,
User1' or something along those lines - and I can get it to do this. The
trouble is, when User2, User3 etc log in, they all still see 'Hello, User1'.
I'm almost certain its to do with my SQL syntax. I can get the page to
display info from the database, but only if it's in the first row of the
database. How do I get the page to display info just for the user who is
actually logging in?
Ok, basics first:
The information is stored in a table called 'core'
The field names I want to display dynamically are called 'username' 'fname'
& 'lname'
Primary id key is called 'id' and is auto increment.
My attempt to get the database to show the information relating only to the
logged in user is as follows:
*********************
SELECT username, fname, lname
FROM core
WHERE core.id = id
*********************
The above is definately not working, plus seems too simple to be right!
Any assistance greatly appreciated. The answer is probably staring me right
in the face but as yet I just cannot see it!
TIA
John H
Re: MySQL Syntax errors
am 08.03.2006 23:39:24 von Shion
John Hopper wrote:
> Hi all
>
> I am currently trying to construct a database-driven membership site. I'm
> using Dreamweaver MX 2004, php & MySQL.
>
> All works well, but what I want the member homepage to do is to say 'Hello,
> User1' or something along those lines - and I can get it to do this. The
> trouble is, when User2, User3 etc log in, they all still see 'Hello, User1'.
>
> I'm almost certain its to do with my SQL syntax. I can get the page to
> display info from the database, but only if it's in the first row of the
> database. How do I get the page to display info just for the user who is
> actually logging in?
>
> Ok, basics first:
>
> The information is stored in a table called 'core'
> The field names I want to display dynamically are called 'username' 'fname'
> & 'lname'
> Primary id key is called 'id' and is auto increment.
>
> My attempt to get the database to show the information relating only to the
> logged in user is as follows:
>
> *********************
> SELECT username, fname, lname
> FROM core
> WHERE core.id = id
> *********************
When a user logs in, I guess they do enter their 'username' and 'password',
when you have verified the 'username' and 'password', do you save the id in a
session/cookie?
$query="SELECT username, fname, lname FROM core WHERE id='$id'";
You need in this case get the id, which we assume you did save in a
session/cookie, and store it in the variable $id.
If you don't do this, then you won't get the right user information, as you
really don't know who the user is after they have logged in. (there aren't
anything really wrong with your SQL statment, so it's more likely you messed
things up in your php code).
//Aho
Re: MySQL Syntax errors
am 08.03.2006 23:45:36 von John Hopper
Hi
Thanks for the response.
To be honest, I am not honestly sure if I am saving the info in a session -
how would I check this and if I'm not, implement it?
Thanks
John H
"J.O. Aho" wrote in message
news:4794p0Fehh8pU1@individual.net...
> John Hopper wrote:
> > Hi all
> >
> > I am currently trying to construct a database-driven membership site.
I'm
> > using Dreamweaver MX 2004, php & MySQL.
> >
> > All works well, but what I want the member homepage to do is to say
'Hello,
> > User1' or something along those lines - and I can get it to do this.
The
> > trouble is, when User2, User3 etc log in, they all still see 'Hello,
User1'.
> >
> > I'm almost certain its to do with my SQL syntax. I can get the page to
> > display info from the database, but only if it's in the first row of the
> > database. How do I get the page to display info just for the user who
is
> > actually logging in?
> >
> > Ok, basics first:
> >
> > The information is stored in a table called 'core'
> > The field names I want to display dynamically are called 'username'
'fname'
> > & 'lname'
> > Primary id key is called 'id' and is auto increment.
> >
> > My attempt to get the database to show the information relating only to
the
> > logged in user is as follows:
> >
> > *********************
> > SELECT username, fname, lname
> > FROM core
> > WHERE core.id = id
> > *********************
>
> When a user logs in, I guess they do enter their 'username' and
'password',
> when you have verified the 'username' and 'password', do you save the id
in a
> session/cookie?
>
> $query="SELECT username, fname, lname FROM core WHERE id='$id'";
>
> You need in this case get the id, which we assume you did save in a
> session/cookie, and store it in the variable $id.
>
> If you don't do this, then you won't get the right user information, as
you
> really don't know who the user is after they have logged in. (there aren't
> anything really wrong with your SQL statment, so it's more likely you
messed
> things up in your php code).
>
>
> //Aho
Re: MySQL Syntax errors
am 09.03.2006 06:28:58 von Shion
John Hopper wrote:
> Hi
>
> Thanks for the response.
>
> To be honest, I am not honestly sure if I am saving the info in a session -
> how would I check this and if I'm not, implement it?
On-line manual session:
http://www.php.net/manual/en/ref.session.php
On-line manual cookies:
http://www.php.net/manual/en/function.setcookie.php
Don't forget to read the user comments for different functions, there are
quite much useful information.
//Aho
Re: MySQL Syntax errors
am 09.03.2006 09:53:45 von John Hopper
Hi
Thanks very much for taking the time to help me!
John H
"J.O. Aho" wrote in message
news:479soqFe6h1dU1@individual.net...
> John Hopper wrote:
> > Hi
> >
> > Thanks for the response.
> >
> > To be honest, I am not honestly sure if I am saving the info in a
session -
> > how would I check this and if I'm not, implement it?
>
> On-line manual session:
> http://www.php.net/manual/en/ref.session.php
>
> On-line manual cookies:
> http://www.php.net/manual/en/function.setcookie.php
>
> Don't forget to read the user comments for different functions, there are
> quite much useful information.
>
>
> //Aho