0

Hi all,

I have a big problem. I am very new to php and sql and I need to create a login web page page for access to a database I have created in mySQL. I have located a script online here: http://php.about.com/od/finishedphp1/ss/php_login_code.htm
that basically explains the entire process. My problem is, I have no idea where to paste the code (eg. what .php pages I need to create and where to paste the code). So far, I have a database named 'waterfor_login' with a table named 'login' and three fields named 'id', 'username' and 'password'. I also have another database called 'waterfor_app1" that I want the user to be able to access.

I know that I will need a login.php page and a logout.php page, but I need to know:
#1. what to place in the login.php page
#2 what to place in the logout.php page
#3 what to place in the members.php page

Also, once the user is logged in, how do I display the contents of the database?

If anyone could help me out with this I would greatly appreciate it!
thank you in advance,
-l.

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Chi-Town
0

firstly write down each pages name, and list the functionality as to what each page should do.

When you have finished this, you should read up on html form methods. To work this with php, you should read up on something called "isset" which determines is something has been clicked.

0

Thanks for your quick reply. I know a little aabout forms and php and I have heard of the isset command.
Right now, all I want to do is set up a login page that verifies the user id and password setup by the user. I have set up a login page called login.html and a page called registration1.php that is called by the form.

Here is my login.html page:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Login Page</title>
</head>

<body>

<form action="registration1.php" method="POST">

<label>username
<input name="username" type="text" id="username" />
</label>
<p>
  <label>pass
  <input name="pass" type="text" id="pass" />
  </label>
</p>
<p>
  <label>pass2
  <input name="pass2" type="text" id="pass2" />
  </label>
</p>
<input name="Submit" type="submit" value="submit" />
</body>
</html>

and here is my registration1.php code:

<? mysql_connect("localhost", "admin", "xxxxxx") or die(mysql_error()); 
 mysql_select_db("app1") or die(mysql_error()); 

 if (isset($_POST['submit'])) { 
 

 if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
 		die('You did not complete all of the required fields');
 	}
 

 	if (!get_magic_quotes_gpc()) {
 		$_POST['username'] = addslashes($_POST['username']);
 	}
 $usercheck = $_POST['username'];
 $check = mysql_query("SELECT username FROM login WHERE username = '$usercheck'") 
 or die(mysql_error());
 $check2 = mysql_num_rows($check);
 

 if ($check2 != 0) {
 		die('Sorry, the username '.$_POST['username'].' is already in use.');
 				}

 	if ($_POST['pass'] != $_POST['pass2']) {
 		die('Your passwords did not match. ');
 	}
 

 	$_POST['pass'] = md5($_POST['pass']);
 	if (!get_magic_quotes_gpc()) {
 		$_POST['pass'] = addslashes($_POST['pass']);
 		$_POST['username'] = addslashes($_POST['username']);
 			}
 

 	$insert = "INSERT INTO login (username, password)
 			VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
 	$add_member = mysql_query($insert);
 ?>

so far, I am getting this error "Parse error: syntax error, unexpected $end in /home3/waterfor/public_html/test/registration1.php on line 41" when I submit the form.

Do you have any ideas why this error would occur??

Edited by lwaterfo: n/a

0

$end means its come to the end of the file unexpectedly.

from a first glance, add a } between line 39 and 40

0

thanks a lot!
looks like the code is running now...
only problem is, the user password and username are not being inserted into the table named 'login'
located in the 'waterfor_login' database.

I have already changed the code in the beginning from:

mysql_select_db("waterfor_app1") or die(mysql_error());

to ...

mysql_select_db("waterfor_login") or die(mysql_error());

any idea why the variables would not be inserted into the table??

0

You have:
"INSERT INTO login (username, password) VALUES ('".$_POST."', '".$_POST."')";

Change to:

"INSERT INTO login (username,password) VALUES ('$_POST[username]','$_POST[pass]')";

Hope this helps

0

Also, try this at the top of the page to connect to the database

$con= mysql_connect("localhost", "userName", "passWord") or die(mysql_error()); 
mysql_select_db("Database_Name",$con);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.