$sql = "select * from `artusers` "
."where `name`='" . $HTTP_POST_VARS['username'] . "' "
."and `pass`='" . $password . "'";
to
$sql = "select * from `artusers` "
."where `name`='" . $HTTP_POST_VARS['username'] . "' "
."and `pass`='" . $HTTP_POST_VARS['password'] . "'";
and
if ( $result = mysql_query($sql) )
{
session_start();
session_register("valid_user");
$valid_user = $HTTP_POST_VARS['username'];
}
to
if ( $result = mysql_query($sql) )
{
if(mysql_num_rows() == 1 && mysql_error() == "")
{
session_start();
session_register("valid_user");
$valid_user = $HTTP_POST_VARS['username'];
}
}
now I've probably already helped too much. If you have book, I suggest consulting it. If not, I like "Core PHP Programming" by Leon Atkinson published by Prentice Hall. ISBN 0-13-089398-6.
I believe there are lots of articles on the internet about logging in a user. There's probably even ready made source code for it at sourceforge.com or phpclasses.com or some other code repository.
Also, try evolt.org, they have nice articles with source code.
Try breaking down your script into its core elements, and accomplish doing each of them separately, before putting them together.
You want to:
retrieve info from a database. Try doing JUST that .
Use a form to post data to the next page.
Use a form to post data to the same page.
Use sessions to retain data across all pages.
Do error checking on your database query.
Display different content based on variables.
Make a test for each little thing you want to do. Only once you completely understand each part proceed to put them together.
When I first started with PHP, I made over a dozen tests to see how arrays worked. Once I saw how things worked, I was able to use it. I also did a script for exactly what you want to do, and I made tests for each little part before I put the whole thing together.
A good test for these things is probably 2 or 3 or 4 lines of code.
For example, to test sessions, try starting a session and registering a variable on the first page. Provide a link to a second page. On the second page, try printing the variable. You could probably do all that with about 5 lines of code, total.