Replaceunsetwith!isset.
george- (02-16-2009)
Great! error gone now
But code still not functioning properly. Refreshes still add to the DBI thought I'd be able to do this but it's not looking too good for me
Thanks for your help thoughit is much appreciated.
Sorry! Replace:
With:Code:$_SESSION['done'] == true;
Code:$_SESSION['done'] = true;
Jeremy | jfein.net
george- (02-17-2009)
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;
}
?>![]()
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>
george- (02-18-2009)
That's fantastic! Thank you Schmoopy!
![]()
Bookmarks