Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Generating name & password

  1. #11
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Replace unset with !isset.
    Jeremy | jfein.net

  2. The Following User Says Thank You to Nile For This Useful Post:

    george- (02-16-2009)

  3. #12
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Great! error gone now

    But code still not functioning properly. Refreshes still add to the DB I thought I'd be able to do this but it's not looking too good for me

    Thanks for your help though it is much appreciated.

  4. #13
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Sorry! Replace:
    Code:
    $_SESSION['done'] == true;
    With:
    Code:
    $_SESSION['done'] = true;
    Jeremy | jfein.net

  5. The Following User Says Thank You to Nile For This Useful Post:

    george- (02-17-2009)

  6. #14
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Hi again Nile,

    Thank you for all your help with this, you've been great! But the code still does not work properly. I feel that I am asking too much with this. I know it's not your problem to work out MY problems!


    Buuutt... in the event that you have a genuine interest in solving it, I won't take that away from you!

    This is the complete code, from start to finish.

    PHP Code:
    <?php
         session_start
    (); 

            
    /*
             *        Generate Username and Password.
             */
         
    $host="localhost";            // Host name
         
    $username="*******";    // Mysql username -removed-
         
    $password="*******";    // Mysql password -removed-
         
    $db_name="*******";     // Database name -removed-


    function generate($string
    {
        
    $output ""// Initialise output variable so it can be added to
        
    if(!isset($_SESSION['user']) || !isset($_SESSION['pass']))
        {
              
    $_SESSION['user'] = ""// Create user / password session variables if not already initialised
               
    $_SESSION['pass'] = "";
        }
        
        for(
    $i 0$i 10$i++)
        {
            
    $r rand(0,1);
            
    $c = ($r==0)? rand(65,90) : rand(97,122); 
            if (
    strlen($_SESSION[$string]) < 10
            
    // Add to the string if a password / username has not already been generated (Less than 10 characters long)
            
    $_SESSION[$string] .= chr($c);
            
    $output .= chr($c);
        }
        return 
    $output// Return the output out of the for loop
    }

         
    $user generate('user');
         
    $pass generate('pass');
         
         
    mysql_connect("$host""$username""$password")or die("cannot connect");
         
    mysql_select_db("$db_name")or die("cannot select DB");

         if(@
    mysql_query("INSERT INTO members (id, username, password) 
         VALUES ('', '
    $user', '$pass')") && !isset($_SESSION['done']))
         {
           
    $_SESSION['done'] = true;
         }
    ?>

  7. #15
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Here you go - tried and tested:

    PHP Code:
    <html>
    <head></head>
    <body>

    <?php
         session_start
    (); 

            
    /*
             *        Generate Username and Password.
             */
         
    $host="localhost";            // Host name
         
    $username="*******";    // Mysql username -removed-
         
    $password="******";    // Mysql password -removed-
         
    $db_name="*****";     // Database name -removed-

         
    if(!isset($_SESSION['done'])) // Set session variable to false if not initialised
         
    {
         
    $_SESSION['done'] = false;
         }

    function 
    generate($string
    {
        
    $output ""// Initialise output variable so it can be added to
        
        
    if(!isset($_SESSION['user']) || !isset($_SESSION['pass']))
        {
              
    $_SESSION['user'] = ""// Create user / password session variables if not already initialised
              
    $_SESSION['pass'] = "";       
        }
        
        for(
    $i 0$i 10$i++)
        {
            
    $r rand(0,1);
            
    $c = ($r==0)? rand(65,90) : rand(97,122); 
            if (
    strlen($_SESSION[$string]) < 10
            
    // Add to the string if a password / username has not already been generated (Less than 10 characters long)
            
    $_SESSION[$string] .= chr($c);
            
    $output .= chr($c);
        }
        return 
    $output// Return the output string that will be inserted into the table
    }

        
    $user generate('user');
        
    $pass generate('pass');
        
         
    mysql_connect("$host""$username""$password")or die("cannot connect");
         
    mysql_select_db("$db_name")or die("cannot select DB");

         if(
    $_SESSION['done'] == false)
         {
            
    $query "INSERT INTO members (id, username, password) 
         VALUES ('', '
    $user', '$pass')";
         
           @
    mysql_query($query);
           
           
    $_SESSION['done'] = true// Set done session to true so the database will not get queried again
         
    }
    ?> 

    </body>
    </html>

  8. The Following User Says Thank You to Schmoopy For This Useful Post:

    george- (02-18-2009)

  9. #16
    Join Date
    Feb 2009
    Posts
    12
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    That's fantastic! Thank you Schmoopy!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •