Hi,
I am a total newbie when it comes to PHP/MySQL.
The project that I am working on requires me to generate a password, insert it and overwrite it in MySQL and then e-mail it out. For the most part it is working, I am e-mailing it and something is being inserted into MySQL, but the field is blank. Its as if the password generator isn't working or I am just missing something in my code. Please take a look. Any help is appreciated at this point!
<?php
$link = mysql_connect("a","b","c");
if (!$link) {
die('I cannot connect to the database beacuse: ' . mysql_error());
}
$db_selected = mysql_select_db("my_db" , $link);
if (!$db_selected) {
die("Can't connect: " . mysql_error());
}
function generatePassword ($length = 5)
{
// start with a blank password
$password = "";
// define possible characters
$possible = "0123456789bcdfghjkmnpqrstvwxyz";
// set up a counter
$i = 0;
// add random characters to $password until $length is reached
while ($i < $length) {
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
// we don't want this character if it's already in the password
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
// done!
return $password;
}
mysql_query("INSERT INTO Table (field) VALUES('$password')")
or die('I cannot insert into the Database because: ' . mysql_error());
$today = date("l, F j, Y");
$message = <<<ENDFORM
Here is the new password for {$today}. Password = {$password}. Visit "http://www.domain.com" and log in.
...
ENDFORM;
$recipient1 = "Me <me@domain.com>";
$recipient2 = "Me <me@domain.com>";
$subject = "The Code for {$today}";
$headers .= "To: $recipent1"."\r\n";
$headers .= "From: $recipient2"."\r\n";
$headers .= "Bcc: $recipient2, $recipient1"."\r\n";
$headers .= "Reply-To: $recipient2"."\r\n";
$headers .= "X-Mailer: PHP-Mailer";
mail( "$recipient1, $recipient2", $subject, $message, $headers);
mysql_close();
?>