Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,241 members, 7,807,813 topics. Date: Wednesday, 24 April 2024 at 07:44 PM

[Code Request] Code for PHP Login And Signup - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / [Code Request] Code for PHP Login And Signup (6430 Views)

Help On Login Code For Php N How To Store On Data Base. / Login Code In Vb6.0 / I Need A Help To Write A Simple Login Form Using Vb.net (2) (3) (4)

(1) (Reply) (Go Down)

[Code Request] Code for PHP Login And Signup by segebee(m): 7:28pm On Mar 11, 2007
does anyone know how to create a signin and signup page
using php-mysql

could u post code and details, thanks
Re: [Code Request] Code for PHP Login And Signup by naijaguru(m): 1:54am On Mar 12, 2007
Creating a signup and sign in require three major steps.

1. Design the forms
2. Design the database
3. Write the code

I will take you through the three process. And aside that, I will also show you an easy way of validating your forms by seperating the forms from the codes. I will also higlight some security tips you need to know when accepting user input via forms, in order to prevent SQL Injections or other attacks. So lets get it rolling.

Supposing I am designing an interactive website for a sports portal, and I need members to signup so they can post comments on news, use the in-built forum, interact and do other stuffs. Then I need to follow the 3 steps above. I will start by designing the form, but before then, we will be creating some files so lets go ahead.

1. signup.php (The code file for processing the form and calling the form using include_once() )
2. signup_form.php (The signup form)
3. login.php (The code for processing the login form and calling just like the signup)
4 login_form.php (The login form)
5. connection.php (The file for the connection details and function for the database),

Make I post this one first before nepa carry light lol
Re: [Code Request] Code for PHP Login And Signup by naijaguru(m): 7:49am On Mar 12, 2007
(Like say I know sey Nepa go carry light. Nepa carry light and I had to continue this tutorial now.)

After creating those files, the next is the database design. Basically you need just one database and one table. I havent planned for this tutorial (which is a bad thing to do when developing systems), so other needs may crop up which would make us create other tables (I hope u know what tables are and how to create them). We will be using MySql for our database table.

If you have xampp installed on your local machine
1. follow this link http://localhost/phpmyadmin (if you dont have xampp, get it @ http://www.apachefriends.org/en/xampp.html )
2. Enter ur username and password if any
3. fill the Create a database form (thats the only input box on the first page)
4. It creates a databse and form there
5. Click on Query or Sql depending on the version of PhpMyAdmin you have and pase this code

CREATE TABLE `user` (
`user_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 255 ) NOT NULL ,
`password` VARCHAR( 255 ) NOT NULL ,
`display_name` VARCHAR( 255 ) NOT NULL ,
`first_name` VARCHAR( 255 ) NOT NULL ,
`last_name` VARCHAR( 255 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`gsm` INT( 15 ) NOT NULL ,
`location` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `user_id` )
) TYPE = MYISAM ;

Query Explanation: I created a Table with 9 columns. The columns are user_id, username, password, display_name, first_name, last_name, email, gsm, location. They are all varchar types except the gsm wich are maily numbers and the user_id (a column specifically added to identfy each user, thats why its set to auto_increment.

Go google for more explanation on SQL or MySql or send in your email for free ebooks. Next is designing the form
Re: [Code Request] Code for PHP Login And Signup by naijaguru(m): 8:51am On Mar 12, 2007
Here is the form:

<form id="sign_up" name="sign_up" method="post" action="signup.php">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="27%">Username</td>
<td width="73%"><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td>Choose Password </td>
<td><input name="password" type="password" id="password" /></td>
</tr>
<tr>
<td>Re-enter Passowrd </td>
<td><input name="password2" type="password" id="password2" /></td>
</tr>
<tr>
<td>Display Name </td>
<td><input name="display_name" type="text" id="display_name" /></td>
</tr>
<tr>
<td>First Name </td>
<td><input name="first_name" type="text" id="first_name" /></td>
</tr>
<tr>
<td>Last Name </td>
<td><input name="last_name" type="text" id="last_name" /></td>
</tr>
<tr>
<td>Email Address </td>
<td><input name="email_address" type="text" id="email_address" /></td>
</tr>
<tr>
<td>GSM</td>
<td><input name="gsm" type="text" id="gsm" /></td>
</tr>
<tr>
<td>Location</td>
<td><input name="location" type="text" id="location" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Sign Up" /></td>
</tr>
</table>
</form>


Note: The name you give to every form element would be used as the variable name in the corrsponding code. So be careful there!
Re: [Code Request] Code for PHP Login And Signup by segebee(m): 6:04pm On Mar 12, 2007
thanks a lot, its really helped

i did oracle so i understand sql but pls explain type= myisam

i can;t wait 4 u to continue

thanks a lot
Re: [Code Request] Code for PHP Login And Signup by naijaguru(m): 1:17am On Mar 13, 2007
[b]MyISAM manages non-transactional tables. It provides high-speed storage and retrieval, as well as fulltext searching capabilities. MyISAM is supported in all MySQL configurations, and is the default storage engine unless you have configured MySQL to use a different one by default.
[/b]http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html

OK. Lets continue.

So far so so good, we have designed the table and designed the form. So lets go on with hooking users from the form into the database. Before that, we'd have to create the connection file so here is the code
here is the code

<?php
$dbName = 'database_name';
$dbUser = 'database_username';
$dbPass = 'database_password';
$dbHost = 'localhost';

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('Mysql Connection failed: ' . mysql_error());
mysql_select_db($dbName) or die("Could not select databse $dbname: " . mysql_error());
?>

You set the username, password, databasename and host variables with the corresponding data. then you call two php in-built functions called mysql_connect(). This is like a key that opens your database by Mr. PHP. The other function is mysql_select_db which selects which databse to use. You can dynamically change databases from your script.

Save this has connection.php and include it in your codes at the top e.g

<?php

include_once 'connection.php';

Next is the signup.php page

//Then your other codes go here

?>
Re: [Code Request] Code for PHP Login And Signup by segebee(m): 7:24pm On Mar 16, 2007
nice work and thanks a lot

though i noticed u stopped

i haven't replied cos i was going through a php book i had bt did noy realise d potential

php is great!

but id like you to explain on how to enable logging out

thanks!

(1) (Reply)

How To Print All Records From A Datagridview In Vb.net / Download Sketchware Pro V6.4.0 Beta 4 Apk / Olode - An Indigenous HTML5 Game

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 32
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.