About these ads

zphp

1.       Define database configuration.  (dbconfig.php)

ob_start();
session_start();
define(‘DBHOST’,’localhost’);
define(‘DBNAME’,’dbname’);
define(‘DBUSER’,’root’);
define(‘DBPWD’,”);

2.       MySQL Class declaration (mysqlclass.php)

class mysqlclass()

{

var $conn;

var $dbc;

var $user;

var $pass;

 

function __construct()

{

$this->connect();

}

 

function connect()

{

$this->conn = mysql_connect(DBHOST, DBUSER, DBPWD) or die (mysql_error());

$this->dbc = mysql_select_db(DBNAME, $this->conn) die (mysql_error());

}

 

function close_conn()

{

if (isset($this->conn))

{

mysql_close($this->conn);

unset($this->conn);

}

}

 

function query($sql)

{

$res = mysql_query($sql);

$this->conf_query($res);

return $res;

}

 

function conf_query($sql)

{

if(!$res)

{

die(mysql_error());

}

}

 

function fetch_array($res)

{

return mysql_fetch_array($res);

}

 

function numrows($res)

{

return mysql_num_rows($res);

}

 

}

 

$db = new database();

 

3.       Login Module (login.php)

<form method=”post” action=”javascript:vlogin()”>

<label>Email Address </label>

<input type=”text” name=”txtuname” id=”txtuname” />

<label>Password</label>

<input type=”password” name=”txtpwd” id=”txtpwd” />

<input type=”submit” name=”sublogin” id=”sublogin” value=”Login” />

<div id=”errmsg”></div><div id=”response”></div>

</form>

 

4.       Ajax – Form validation  (ajaxjs.js)

function createObject()

{

var request_type;

var browser = navigator.appName;

if (browser == “Microsoft Internet Explorer”)

{

request_type = new ActiveXObject(“Microsoft.XMLHTTP”);

}

else

{

request_type = new XMLHttpRequest();

}

return request_type;

}

 

var http = createObject();

var nocache = 0;

 

function vlogin()

{

document.getElementById(“errmsg”).innerHTML = “”;

document.getElementById(“response”).innerHTML = “Loading…”;

nocache = Math.random();

 

var email = encodeURI(document.getElementById(“txtuname”).value);

var pwd = encodeURI(document.getElementById(“txtpwd”).value);

 

http.open(‘GET’,’loginres.php?email=’+email+’&pwd=’+pwd+’&nocache=’+nocache);

http.onreadystatechange = vloginReply;

http.send(null);

}

 

function vloginReply()

{

if(http.readyState == 4)

{

var response = http.responseText;

if(responseText == 0)

{

document.getElementById(‘errmsg’).innerHTML = ‘<font color=red>Verify email address and password</font>’;

document.getElementById(‘response’).innerHTML = “”;

}

else if(response == 1)

{

document.getElementById(‘errmsg’).innerHTML = ”;

document.getElementById(‘response’).innerHTML = ‘<font color=green>Login successfully!.</font>’;

setTimeout(“fredir()”, 1000);

// document.getElementById(‘login’).style.display = ‘none’;

}

}

}

 

function fredir()

{

window.location = “index.php”;

}

 

5.       Login verification from Ajax(loginres.php)

if ($_GET[‘email’] && $_GET[‘pwd’])
{
$email = $_GET[‘email’];
$pwd = $_GET[‘pwd’];
$result = $db->query(“select * from table where emailaddress = ‘”.mysql_real_escape_string($email).”’ and password = MD5(‘”.mysql_real_escape_string($pwd).”’)”);

if ($db->numrows($result) == 1)
{
$row = $db->fetch_array($result);
$_SESSION[‘id’] = $row[‘gid’];
$_SESSION[‘name’] = $row[‘name’];
echo ‘1’;
}
else
{
echo ‘0’;
}

}

6.       Display records from database table (display.php)

$result = $db->query(“select * from table”);

echo $db->numrows($result);

while ($row = $db->fetch_array($result))

{

echo $row[‘fieldname’];

}

 

7.       Insert form values into database (insert.php)

$name = $_REQUEST[‘name’];

$email = $_REQUEST[‘email’];

$db->query(“insert into table (name, email) values (‘$name’,’$email’)”);

echo “inserted”;

 

8.       Logout (logout.php)

if (empty($_SESSION[‘gid’]))

{

header(“location:index.php”);

}

 

session_start();

session_unset();

session_unregister();

session_destroy();

header(“location:index.php”);

 

About these ads

5 Responses

  1. Mate thanks for such a good article. I do agree with it

  2. I really want to get my greasy paws on this! I can already feel my grades going down until I finish the game!

  3. I’ve been gone for some time, but now I remember why I used to love this site. Thank you, I will try and check back more frequently. How frequently do you update your website?

  4. I need to test

  5. Thanks ! Supper Post !!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: