Help with login system

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu May 31, 2012 9:01 am

Help with login system

Postby KevinHoughton » Thu May 31, 2012 9:06 am

Alright, hi there.

I have to be honest, I'm not a proffesional PHP & MySQL scripter so that's why i am asking help here.
I am trying to create a login system.

Code: Select all



require 'connect.php';

   // Checking whether the Login form has been submitted
   $err = array();
   // Will hold our errors
   if(!$_POST['username'] || !$_POST['password'])
      $err[] = 'All the fields must be filled in!';
      $_POST['username'] = mysql_real_escape_string($_POST['username']);
      $_POST['password'] = mysql_real_escape_string($_POST['password']);
      $_POST['rememberMe'] = (int)$_POST['rememberMe'];
      // Escaping all input data
      $row = mysql_fetch_assoc(mysql_query("SELECT * FROM PlayerData WHERE Name='{$_POST['username']}' AND Password='{$_POST['password']}'"));

         // If everything is OK login
         $_SESSION['rememberMe'] = $_POST['rememberMe'];
         // Store some data in the session
      else $err[]='Wrong username and/or password!';
   $_SESSION['msg']['login-err'] = implode('<br />',$err);
   // Save the error messages in the session

   header("Location: index.php");

// Starting the session

// Making the cookie live for 2 weeks


if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
   // If you are logged in, but you don't have the tzRemember cookie (browser restart)
   // and you have not checked the rememberMe checkbox:

   $_SESSION = array();
   // Destroy the session

   $_SESSION = array();
   header("Location: index.php");

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transporter Roleplay</title>
<style type="text/css">
a:link {
   text-decoration: none;
a:visited {
   text-decoration: none;
a:hover {
   text-decoration: none;
a:active {
   text-decoration: none;
<style type="text/css">
* {
   margin: 0;
   padding: 0;   

body {
   background-image: url(images/background.jpg);

#right {
   float: right;   
#center {
   border-radius: 0px 0px 10px 10px;
   width: 1200px;
   border-left-width: 3px;
   border-left-color: #666;
   border-left-style: solid;
   border-right-width: 3px;
   border-right-color: #666;
   border-right-style: solid;
   border-bottom-style: solid;
   border-bottom-color: #666;
   border-bottom-width: 3px;
   min-height: 900px;
   margin: auto;
   background-color: white;
   margin-bottom: 50px;

#header {
   width: 1200px;
   height: 150px;

.navbar {
   height: 40px;

.navbar ul {
   min-width: 100px;
   color: white;
   font-weight: bold;
   font-family: verdana;
   padding-top: 10px;
   height: 30px;   
   float: left;
   text-align: center;
   margin-left: 10px;
   padding-left: 10px;
   padding-right: 10px;

.navbar ul:hover {
   background-image: url(images/navbar_hover.jpg);   

footer {
   width: 100%;
   height: 30px;
   bottom: 0;
   padding-top: 10px;
   position: fixed;
   text-align: center;
   color: black;
   font-weight: bold;
   font-family:Verdana, Geneva, sans-serif;
   margin-top: 50px;
<div id="center">
  <div id="header"></div>
  <div class="navbar">
     <a href=""><ul>Home</ul></a>
    <a href=""><ul>Forums</ul></a>
    <a href=""><ul>Server team</ul></a>
    <a href="#"><ul>Community</ul></a>
    <a href="#"><ul>Patrocinations</ul></a>
    <a href=""><ul>Donations</ul></a>
    <a href="#"><ul>About us</ul></a>
    <a href="samp://"><ul id="right">Click here to play now!</ul></a>

<center><form class="clearfix" action="" method="post">
               <h1>Member Login</h1>
                     echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
               <label class="grey" for="username">Username:</label>
               <input class="field" type="text" name="username" id="username" value="" size="23" />
               <label class="grey" for="password">Password:</label>
               <input class="field" type="password" name="password" id="password" size="23" />
                  <label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> &nbsp;Remember me</label>
                 <div class="clear"></div>
               <input type="submit" name="submit" value="Login" class="bt_login" />
             <li>Hello <?php echo $_SESSION['Name'] ? $_SESSION['Name'] : 'Guest';?>!</li>
<footer>Transporter Roleplay &copy; 2012, All rights reserved.</footer>

You can check the log-in @ with demo-account: "demo" and password: "demo1234"

It will not work because I actually don't know, that's why I posted my script here.

I hope someone can teach me how to fix this, or just help me.

Many thanks, Kevin

PS. I am new on this forum so I don't know if this is the correct section to post it.

User avatar
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Help with login system

Postby Nullsig » Thu May 31, 2012 10:54 am

This line: "session_start();" Needs to be the first line of the PHP script.

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest