Reply to Re: MySQL Syntax errors

Your name:

Reply:


Posted by J.O. Aho on 03/09/06 00:39

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация