php and mysql help

jac904

New Member
Messages
25
Reaction score
0
Points
0
Hi,I have created a members page and mysql db for my site and was wondering how to get the code for page and where to acutally insert code in order for page to work.This is very new to me.
 

jac904

New Member
Messages
25
Reaction score
0
Points
0
I wanted to make a members page on my where people had to create a login to become part of site.I watched a video and made mysql members data base in phpadmin.This is where i'm stuck,i wanted to know how to put this onto my site but not sure how to go about it.I don't know where to get the code or where to put it on site builder ,unless there is another way to create a working member page.
 

bvkhunt11

New Member
Messages
6
Reaction score
0
Points
0
So is the login working? Do you need to know how to create login page or how to create database in phpmyadmin? Or do you need to know how to upload the database to the web server??
Please be clear...
 

zerostrike

New Member
Messages
6
Reaction score
0
Points
0
Do you mean you want a Register page and a login page?

Kindly be specific so we can help/assist you in any way we can. :)
 

jac904

New Member
Messages
25
Reaction score
0
Points
0
A login and register page is what i want.I made this in phpmyadmin, but don't know what to do with it.

ID int(11) No
usename varchar(255) No
sign_up_date datetime No
email varchar(255) No
bio text Yes NULL
account_permissions enum('a', 'b', 'c') No b
email_activation enum('0', '1') No 0
password varchar(255) No
lastlogin datetime No

This is my first time dealing with this while making a site.Very new to me.

Thank you for the help.
 

er.rohittank22

New Member
Messages
4
Reaction score
0
Points
0
First of all create a database and Run this sql query in Phpmyadmin then follow next steps...

CREATE TABLE IF NOT EXISTS `members` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`sign_up_date` datetime NOT NULL,
`email` varchar(255) NOT NULL,
`bio` text,
`account_permissions` enum('a','b','c') DEFAULT NULL,
`email_activation` enum('0','1') DEFAULT NULL,
`password` varchar(255) NOT NULL,
`lastlogin` datetime DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



Now Make your web pages as....
....................................................................................
-------------------For SignUp---------------------

save this as 'signup.php'

<h3 align='center'>Signup for a New Account</h3>
<h4 align='center'>Please fill given details below:</h4>
<form id='regForm' name='regForm' method='post' action='registerit.php'>

<table width='600' border='0' cellpadding='2' cellspacing='0' align='center'>

<tr>
<th>*Email </th>
<td><input name='email' type='text' class='textfield' id='email' /></td>
</tr>
<tr>
<th>*Username</th>
<td><input name='username' type='text' class='textfield' id='username' /></td>
</tr>
<tr>
<th>*Password</th>
<td><input name='password' type='password' class='textfield' id='password' /></td>
</tr>
<tr>
<th>*Confirm Password </th>
<td><input name='cpassword' type='password' class='textfield' id='cpassword' /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type='submit' name='Register' value='Register' /></td>
</tr>
</table>
</form>
------------------------------------------------------------------------
Save this as registerit.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'YOUR_DATABASE_USERNAME'); //Change Username with Your
define('DB_PASSWORD', 'YOUR_DB_PASSWORD'); //Change Password with Your
define('DB_DATABASE', 'YOUR_DB_NAME'); //Change Database name with Your
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_DATABASE);


$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
$date=date('Y-m-d h-i-s A');

if($password==$cpassword)
{
$q = mysql_query("insert into members (email,username,password,sign_up_date) values('$email','$username','$password','$date')");
if ($q)
{
echo "<h2>Registration Successfull</h2>
<a href='index.php'> Click to Login</a>";
}
else
{
echo "Something wrong with Query";
}
}
else
{
echo "<h3>Password Not Match</h3>
}
?>

---------------------------------------------------------------------------------
-------------------For Login---------------------
Save this as 'index.php'

<h3 align='center'>Login</h3>

<form id='loginForm' name='loginForm' method='post' action='loginit.php'>

<table width='600' border='0' cellpadding='2' cellspacing='0' align='center'>


<tr>
<th>*Username</th>
<td><input name='username' type='text' class='textfield' id='username' /></td>
</tr>
<tr>
<th>*Password</th>
<td><input name='password' type='password' class='textfield' id='password' /></td>
</tr>

<tr>
<td>&nbsp;</td>
<td><input type='submit' name='Login' value='Login' /></td>
</tr>
</table>
</form>

--------------------------------------------------
Save this as loginit.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'YOUR_DATABASE_USERNAME'); //Change Username with Your
define('DB_PASSWORD', 'YOUR_DB_PASSWORD'); //Change Password with Your
define('DB_DATABASE', 'YOUR_DB_NAME'); //Change Database name with Your
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_DATABASE);

session_start();

$username = $_POST['username'];
$password = $_POST['password'];
$sql = mysql_query("SELECT * FROM members where username='$username' && password='$password'");
if(mysql_num_rows($sql)==1)
{
session_regenerate_id();
$member = mysql_fetch_assoc($sql);
$_SESSION['SESS_MEMBER_ID'] = $member['id'];
$_SESSION['SESS_EMAIL'] = $member['email'];
$_SESSION['SESS_USERNAME'] = $member['username'];
session_write_close();
header("location: logged.php");

}else {

echo "Username Password Not Matched";

}
?>

-----------------------------------------------------------------------------------------
Save this as 'logged.php'
<?php
//Start session
session_start();

if($_SESSION['SESS_USERNAME'] == '') {
header("location: access-denied.php");
exit();
}
else
{
echo "Welcome $_SESSION[SESS_USERNAME] You are Logged in";
echo "<br /><a href='logout.php'>Logout</a>";

}
?>

---------------------------------------------------------
Save it as 'logout.php'
<?php

//Start session
session_start();
unset($_SESSION['SESS_MEMBER_ID']);
unset($_SESSION['SESS_EMAIL']);
unset($_SESSION['SESS_USERNAME']);
//Unset the variables stored in session

echo "<h1>Logout </h1>
<p align='center'>&nbsp;</p>
<h4 align='center' class='err'>You have been logged out.</h4>";

?>

-----------------------------------------------------------
Save it as 'access-denied.php'
<?php
echo "<h3>Access Denied</h3>";
?>

-------------------------------------------------------------------------------------
I think that this will solve your problem... enjoy...
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Do NOT use er.rohittank22's code. It is incredibly insecure (vulnerable to SQL injection, vulnerable to session hijacking, stores passwords as plaintext). It also uses the outdated (and soon-to-be deprecated) mysql extension. It's a great example of why you shouldn't do this yourself for production sites. You should design and build a login system only to learn or if you've a strong understanding of security issues.

The topic of logins and user systems has been covered many times before on this forum. Search for relevant threads to get better answers.
 
Last edited:
Top