Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone know Tutorial Sites? Specially for user login/pass functions?

Status
Not open for further replies.

lukelukeluke

Technical User
Joined
Dec 23, 2003
Messages
117
Location
CH
Hello everyone

I know only a bit about PHP / Mysql up to now
I know how to put some data inside a database or how to display some data from a database.
What i would liked to do was a login and password form, where users can login, view theyr own user settings
and every user has his own page and his own settings.

I dont want anyone to post how to do this here (would be stupid wouldnt it? ;)

But if anyone knows a site with VERY GOOD!!! tutorials for php (in cooperaction with mysql),
then it would be cool to know them.
(I searched in google for tutorials but all i found was some courts where you have to pay...)

Thanks to everyone who knows good tutorial sites!
 
I can give you pseudo code and post the complete code tonight (dont' have access as I'm at work). I broke it into two pages...one to logon and one to register on the site....

Note I like to place all the code into functions

Code:
logon.php
session_start();
if (!$POST['submit']){ //submit button not pressed
  show_form();
}else{
  logon();
}
function show_form()
{
//.html code to show the logon form
?>
<form name=logon action=PHP_SELF method=post>
<table><tr><td>
UserName </td><td><input type=text name=uname></td></tr>
<tr><td> 
Password</td><td><input type=pass name=pword></td></tr>
<tr><td colspan=2 align=center><input type=submit name=submit value=logon></td></tr></table>

<?}
function logon()
{
//get data from form
$uname=$_POST['uname'];
$pass = $_POST['pword'];
//validate data - check for alphanumeric only etc
//query the db for logon
//db connection here unless abstracted to another page
$sql= "select * from users where username='$uname' and pass='$pword'";
$result= mysql_query($sql);

  if (($result)&&(mysql_num_rows($result)==1)){  //there is a positive result
  while ($row = mysql_fetch_array($result)){
    $SESSION['user_id'] = $row['user_id'] //succesful logon}
  }else{
    echo "logon failed"
    show_form();
  }

}



}



Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top