Jump to content

Login script help


addinol

Recommended Posts

Hey, could someone help me with login script ? I've got registration script.

 

It contains 3 files:

 

reg.php

<?php

require_once 'database.php';
?>

<h1><strong>Register</strong></h1>

<form name="register" method="post" action="regcheck.php">

  <label>
  <input type="text" name="user" id="user"> Username<br />
  </label>
  
  <br />
  
  <label>
  <input type="password" name="pass" id="pass"> Password<br />
  </label>
  
  <br />
  
  <label>
  <input type="text" name="email" id="email"> Email<br />
  </label>
  
  <label>
  <input type="submit" name="reg" id="reg" value="Register">
  </label>
  
</form>

 

regcheck.php

<?php
$email = $_POST['email'];

if(
    isset( $_POST['user'] ) &&
    isset( $_POST['pass'] ) &&
    isset( $_POST['email'] )
)
{
    if( strlen( $_POST['user'] ) < 4 )
    {
        echo "Username is too short";
    }
    elseif( strlen( $_POST['pass'] ) < 4 )
    {
        echo "Password is too short";
    }
    elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
    echo "Bad email address";
}  
    elseif( $_POST['pass'] == $_POST['user'] )
    {
        echo"Username and password can't be the same";
    }
    else
    {
        include( 'database.php' );

        $username = mysql_real_escape_string( $_POST['user'] );
        $password = mysql_real_escape_string( $_POST['pass'] );
        $email = mysql_real_escape_string( $_POST['email'] );

        $sqlCheckForDuplicateN = "SELECT username FROM user WHERE username = '". $username ."'";
	$sqlCheckForDuplicateE = "SELECT email FROM user WHERE email = '". $email ."'";
        
        if( mysql_num_rows( mysql_query( $sqlCheckForDuplicateE ) ) == 0 && mysql_num_rows( mysql_query( $sqlCheckForDuplicateN ) ) == 0 )
        {
            $sqlRegUser =     "INSERT INTO
                        user( username, password, email )
                    VALUES(
                        '". $username ."',
                        '". $password ."',
                        '". $email ."'
                        )";

            if( !mysql_query( $sqlRegUser ) )
            {
                echo "You Could Not Register Because Of An Unexpected Error.";
            }
            else
            {
                echo "You Are Registered And Can Now Login";
            }
        }
        elseif( !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateE ) ) == 0))
        {
            echo "The Email You Have Entered Is Already Being Used. Please Try Another One.";
        }
        elseif( !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateN ) ) == 0))
        {
            echo "The Username You Have Entered Is Already Being Used. Please Try Another One.";
        }
        elseif( !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateE ) ) == 0) && !(mysql_num_rows( mysql_query( $sqlCheckForDuplicateN ) ) == 0))
        {
            echo "The Email and Username You Have Entered Is Already Being Used. Please Try Another One.";
        }
        
        
    }
}
else
{
    echo "You Could Not Be Registered Because Of Missing Data.";
}
?>

 

database.php

<?
$con = mysql_connect('host','username','password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('dbname');
?>

 

 

So could someone help me with login ???

 

 

 

 

 

Link to comment
Share on other sites

This is more of a forum for learning how to do PHP, and not really for people just doing it for you.

 

If you really want to learn, start writing some code and ask for help along the way.

 

If you want someone to just do it for you, try the Freelance area.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.