Database Handling

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NewinPHP
Forum Newbie
Posts: 3
Joined: Mon Jun 06, 2005 2:21 am

Database Handling

Post by NewinPHP »

Hi,
New to PHP if you could please let me know how do we write in php to create a Login form and store it in a sql database.

Thanks,
I will really appreciate it.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Theres quite a bit you need to do for this. Read Sessions.

Code: Select all

<form action=&quote;auth.php&quote; method=&quote;post&quote;>
<input type=&quote;text&quote; name=&quote;username&quote;/>
<input type=&quote;password&quote; name=&quote;password&quote;/>
<input type=&quote;submit&quote; name=&quote;btn&quote; value=&quote;Login&quote;/>
</form>
auth.php

Code: Select all

// Connect to the db
mysql_connect($host,$db_username,$db_password) or die("Could not connect to the Database");
mysql_select_db($db_databasename) or die("Could not select database");
// Do all the checking for username and password - $_POST['username'] and $_POST['password']
mysql_query("INSERT INTO 'LoginStats' VALUES()");
session_module_name("user");
session_set_save_handler("Session_Open","Session_Close","Session_Read","Session_Write","Session_Remove","Session_GC");
session_start();
Have all your session functions in some file - asssuming you are writing sessions to db and not using files.

Code: Select all

function Session_Open($path,$name)
 {
 }
function Session_Close()
 {
 }
function Session_Read($id)
 {
 }
function Session_Write($id,$data)
 {
 }
function Session_Remove($id)
 {
 }
function Session_GC($life)
 {
 }
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

by putting the sessions in any file you mean just save them with any name like sessions.php? im confused
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

The session functions can be anywhere as long as you include it in your scripts.
Sessions can be stored either in a file or in a db.
Session stored in files will be in some tmp folder while for db you'll have to define the functions to handle session handling.
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

ok thanks :D
Post Reply