Make Login Page

sweet92

New Member
Messages
12
Reaction score
0
Points
0
could somebody help me, i want to make a login page for my site but i dont know where to start, im using dreamweaver to build this login page, i know there has to be database and the page checks the details against this database but how do you create and add data to this database and get the login page to work
 

sweet92

New Member
Messages
12
Reaction score
0
Points
0
well sorry! theres no need to be rude and btw i already DO know how to google im not thick!
also i have already tried a tutorial it didnt work so i thought id ask here instead
 
Last edited:

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Just tell us what didn't work and we'll work from there. Post the code you already have so we can see what needs to be added or changed.
 

sweet92

New Member
Messages
12
Reaction score
0
Points
0
firstly i made the file loginpage.php , not sure if the code is important for this bit but ill add just in case
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

then i tried to make checklogin.php, i think this is where i went wrong and i got confused, the code i tried to use was this, the code is from the tutorial i tried and failed on

<?php
$host="fashion.x10hosting"; // Host name
$username=""; // Mysql username <<Unsure about this bit
$password=""; // Mysql password
$db_name="Accountinfo"; // Database name
$tbl_name=""; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

and i didnt really get much further than that i have made the database and loginsuccess.php, im pretty new to scripts so not very sure about if i need to edit any bits
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
firstly i made the file loginpage.php , not sure if the code is important for this bit but ill add just in case
no problems with the form.
then i tried to make checklogin.php
Why not keep the code in the same page as the form?
PHP:
$username=""; // Mysql username <<Unsure about this bit

username is usually a mixture of your main account name and your db username (yourmainusername_databaseusername)

PHP:
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
Try to use the MySQL error function wherever possible - it will help you loads...

PHP:
or die(mysql_error())

Try getting the connection first...

There are a few people on here that will try to help as much as possible (for some strange reason! :nuts:)
 

Zenax

Active Member
Messages
1,377
Reaction score
4
Points
38
freecrm has already clarified most of the things required to make a login page.

The first thing that you need to do is create a Login screen. You can do this either using the design view or the code view of dreamweaver. Once you have this, then you are ready to add in the PHP code needed to make the login work.

The first thing to do is to make a database that is going to contain the login information. This is done by running SQL commands in MySQL under the cPanel belonging to your account.

Code:
CREATE TABLE users (ID MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(60), password VARCHAR(60))

This is only a basic SQL statement that you could use. If you want extra fields on your registration form then you need to add extra fields into your database.

The next part of the build is to build a registration form to enable you to enter information into the database, that you can then use to login with.

The only fields you are going to need are a username one and a password field.

Code:
<input type="text" name="user" />
<br />
<input type="password" name="password" />
<br />
<input type="button" name="submit" value="Register!" />

That code above creates a simple basic register form. You need to include the registration code that you are going to add in a seperate page.

register.php

First the connection:
PHP:
$db[user] = "cPanel username here";
$db[pass] = "cpanel password here";
$db[host] = "localhost";
$db[dbname] = "name of database. Normally begins with your cPanel name";

$db_conn = mysql_connect("$db[host]", "$db[user]", "$db[pass]")or die("cannot connect"); 

$db_select = mysql_select_db("$db[dbname]")or die("cannot select DB");

That creates the connection to the database and then shows any erros if there are any when you are connecting to your database.

Now you have to add an insert statement into the register.php file in order to get the information that has been entered into the form into the database.

Now I aint very good with PHP so you shall have to serach google onto how to insert statements with sql using variables.

You can add extra features to the register.php file in order to make the registration more secure, such as md5 hash encryption. This is really useful on things such as passwords etc.

In the login page you need to add code to match the the entered info with that in the database!

Again me not being good with PHP and a it being a long time since I created something like this, a lot of google research will be needed when creating this.

Post back if you need more help and we shall see what we can do!
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
then to register username and password, I'd say to use
PHP:
$_SESSION['user']['username'] = $username;
$_SESSION['user']['password'] = $password;
You might as well consider encrypting your passwords for added security.
 

natsuki

New Member
Messages
112
Reaction score
0
Points
0
Zenax found the problem, you should use 'localhost' as hostname (if both database and files are on x10hosting).
 

sweet92

New Member
Messages
12
Reaction score
0
Points
0
thanks alot for helping me but when i put this on my site i get an warning saying it cant connect to the database have also created a bulletin board along with login page that has an warning also along the same lines, do i need to update my php to get this to work? im on the basic php at the moment.
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
Ah you see you didn't say you had a problem already. You're opening post reads to me as "I want login page. You make me one." and that seriously peeves me off.

What is the exact error? Remember, database names have your x10 username first (see exactly what it's called in phpMyAdmin).
 

sweet92

New Member
Messages
12
Reaction score
0
Points
0
oh ya know what i give up! when i ask a question i get someone like you taking the p*** and being funny and anyway thats the error/problem i had in the first place it HASNT gone away and all was saying was the same error was on my message board that i created as they both use the same database! and again i was asking did i need to update my php to get the login page to work properly, is there something wrong with asking a question here?.
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
I chastised you for the following comments "i want to make a login page for my site but i dont know where to start" and "how do you create and add data to this database and get the login page to work". These are synonymous with "I can't be arsed to actually teach myself these things, do it for me!" This forum is for help, not teaching. We have a tutorial board for that.

Now, take a chill pill and answer my question: What's the exact error? Have you changed anything in the code?

Also - add some punctuation, naming and spacing, it's very difficult to actually understand what you want. Something about scripts getting confused because they're sharing a database is all I can make out.
 

sweet92

New Member
Messages
12
Reaction score
0
Points
0
"I can't be arsed to actually teach myself these things, do it for me!" - im not asking anybody to teach me, all i said was i didnt know where to start with it, this was as the tutorial i was trying to TEACH MYSELF off wasnt very clear, but theres no point posting the error now as i have now got the page working, i think there was a problem with the database itself rather than the script, as i last night i created a new database and the page doesnt show any errors and logs in.
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
I realise that - I was explaining my outburst as that's how your post read to *me*

Although I'm glad you fixed the problem. Shame you didn't find out what was causing it though, would have been good to learn from :)
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
thanks alot for helping me but when i put this on my site i get an warning saying it cant connect to the database have also created a bulletin board along with login page that has an warning also along the same lines, do i need to update my php to get this to work? im on the basic php at the moment.

I don't think you need to be on anything higher than basic for DB connection.

It's far more likely your settings are wrong.

Having said that, I've been on intermediate for a while...;)
 

sweet92

New Member
Messages
12
Reaction score
0
Points
0
im not very experienced with php so i really dont know what exactly was wrong but maybe the database became corrupted or something, also i have updated my php version to intermediate so as i did that and changed the database at the same time im not exactly sure which was the problem lol.
 
Top