Login for a website (mysql)

Discussion in 'PHP and MySQL' started by krisakaklp, Aug 18, 2010.

  1. krisakaklp New Member

    well heyy,,

    i remember working for my old clan and i went through some php codes, and well because i used to work in the commuinities that do this its very simply :)
    use it have fun enjoy it spread it :)

    PHP CODE -
    <?php
    // User information and settings
    $DatabaseSettings = array( 'Server' => "localhost",
    'User' => "root",
    'Password' => "",
    'Database Name' => "logintest");
    //
    User information and settings

    // Login
    session_start();

    // Connecting
    mysql_connect($DatabaseSettings['Server'], $DatabaseSettings['User'], $DatabaseSettings['Password']) || die("<b>&gt;</b> Database Connection Failed.");
    if(!
    mysql_select_db($DatabaseSettings['Database Name'])) {
    // Simple hack to make the database if we're root
    if($DatabaseSettings['User'] == "root") {
    mysql_query("CREATE DATABASE `".$DatabaseSettings['Database Name']."`;") || die("<b>&gt;</b> Database Creation Failed.");
    } else
    die(
    "<b>&gt;</b> Database Selection Failed.");
    }

    // Check if the table exists
    $result = mysql_query("SHOW TABLES FROM `".$DatabaseSettings['Database Name']."` LIKE 'logindata';");
    if(
    mysql_num_rows($result) == 0) {
    mysql_query("CREATE TABLE `logindata` ( `userid` INT(3) AUTO_INCREMENT PRIMARY KEY, `username` VARCHAR(50), `password` VARCHAR(50) );") || die("<b>&gt;</b> Failed to create logindata table.");
    mysql_query("INSERT INTO `logindata` (`username`, `password`) VALUES ('test', '".md5("test")."');") || die("<b>&gt;</b> Failed to insert row into logindata table.");


    PHP CODE ^^^^^

    so how do i link my username and password to this? easy
    -------------------------------------------------------------------------------
    ---------------------PHP CODE----------------------------------------------
    <form action="" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="password" /><br />
    <
    input type="submit" name="submit" value="Login" /> <a href="?do=register">Register</a>
    </
    form>
    -------------------------------------------------------------------------------
    ---------------------PHP CODE----------------------------------------------

    with.

    use these in your index.html however rename it to index.php and then nice :)

    here is a logging blah for you i aint added this to the codee like and tested it as im busy with my site, but il try in my spare time.

    credits for code

    me,mupp,crx,slates
    mombot(C)


    Kris Aka KLP <3

    Attached Files:

  2. krisakaklp New Member

    btw if you have ANY quesitons or problems pm me here or on my email
    mombot_klp@hotmail.co.uk il try to get back to you at the moment im very busy, and sometines not on computer.
  3. You can put information in the database and then put it login name and password for it.