View unanswered posts | View active topics It is currently Sun Dec 16, 2018 8:33 pm

Reply to topic  [ 1 post ] 
 Register & Login W/ SCRIPTS! And db included! 
Author Message
Junior Member

Joined: Sun Sep 13, 2009 4:08 pm
Posts: 54
Location: United States Of America
Post Register & Login W/ SCRIPTS! And db included!
Ok, this will be a HUGE tutorial, but I am doing it, lets start.
Our first script is creating our database, do not change anything here except your Database connection.
Put this in some random file, refresh the page, and you should have the database setup.
$con = mysql_connect("","root","root"); //Change your info <<
if (!$con)
die('Could not connect: ' . mysql_error());

if (mysql_query("CREATE DATABASE Users",$con))
echo "Database created";
echo "Error creating database: " . mysql_error();

// Now we create the table
mysql_select_db("Users", $con);
$sql = "CREATE TABLE Users
id int,
Username varchar(20), //You can set these lengths to how you want them
Password varchar(20),
FirstName varchar(20),
LastName varchar(20),
//Id should be set to auto increment, so once you enter your database, go inside, and change
// the id to Primary Key, and auto increment. Thanks.

// Ok, now we have our simple Database created, now on to another script.

// Execute query
[/PHP]Ok, the next script is were you are going to register.

Post.php is the file name :) Remember, this is the register page.
[HTML] <form action='Received.php' method='Post'>
Username: </br> <input type='Text' name='Username'> </br>
Password: </br> <input type='password' name='Password'> </br>
Firstname: </br> <input type='text' name='Firstname'>
Lastname: </br> <input type='text' name='Lastname'>
</br><input type='submit' value='Register'>
</form>[/HTML]Ok, now we are going to have to access the database so we can tell that the information has been recieved. So the next script is:

[PHP] <?php
$con = mysql_connect("","root","root"); //remem to change


$sql = "INSERT INTO Users (Username, Password, Firstname, Lastname)

if (!mysql_query($sql,$con))
die('Could not register');
echo "You have successfully registered!";


[/PHP]By the way, I made these scripts, so if there is any errors, just contact me somehow.

Alright, next is the login script. This is quite a big one:

login.php NOTE: This is the script, not the fields!


$Username = $_POST['Username'];
$Password = $_POST['Password'];

if ($Username&&$Password)

$connect = mysql_connect("","root","root") or die("Couldn't connect to database");
mysql_select_db("Users") or die("Couldn't find Database");

$sql = "INSERT INTO Users (Username, Password, Firstname, Lastname)

$numrows = mysql_num_rows($query);

if ($numrows!=0)

while ($row = mysql_fetch_assoc($query))
$dbusername = $row['Username'];
$dbpassword = $row['Password'];

$sql = "INSERT INTO Users (Title, Name, Body)

// check to see if they match
if ($username==$dbusername&&$password==$dbpassword)
echo "Welcome, $Username! <a href='member.php'>Click</a> here to enter the member page.";
echo "Incorrect password!";

die("That user doesn't exist!");

die("Please enter a username and a password.");

?>[/PHP]Alright, now next is the logout.





echo "You've been logged out. <a href='index.php'>Click</a> here to return.";

?>[/PHP]Now the member page:



if ($_SESSION['Username'])
echo "Welcome, ".$_SESSION['Username']."!
<a href='logout.php'>Logout</a>";
die("You must be logged in!");
?>[/PHP]Next, is the login fields:


<form action='login.php' method='post'>
<input type='text' name='Username'>
<input type='password' name='Password'>
<input type='submit' value='login'></br>

</html>[/HTML]Alright, thats about it! Thanks for looking! - Spencer Chase. Feel free to ask for more tutorials!

Thu Dec 31, 2009 12:32 pm
Report this post
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
© Copyright 2003-2008 The ultimate PHP Editor and PHP IDE site.