PDA

View Full Version : What's wrong with this code?


isman
08-25-2002, 05:33 PM
This little tidbit of code is part of the IB3 import script. It's supposed to email the imported users their new password but the username and password fields are blank.

I've been racking my brain on this for two days and can't figure it out. I was hoping a fresh pair of eyes might be able to spot it.
if ($action == "passwords") {
$emailmessage =
"Hello,

Today $bbtitle has been upgraded blah blah blah. Your new password is below:

Username: \$username
Password: \$password

You can change the password at this address:

$bburl/usercp.php

Thank you for your co-operation, and apologies for any inconvenience caused.

Best Regards,

$bbtitle Team";

doformheader("bbimport_ib3", "dopasswords");
maketableheader("Step 8: Update User Passwords");
makehiddenfields();
makedescription("Ikonboard uses a non-reversible password encryption blah blah blah");
maketextareacode("Email Subject", "emailsubject", "$bbtitle Password Update");
maketextareacode("Email To Send", "emailmessage", stripslashes($emailmessage));
makeinputcode("Number of users to email per cycle:","perpage","25");
makeyesnocode("Send Emails (set to no if you are testing)", "reallysend", "1");
makedescription("If you want to skip this step, please click ".makelinkcode("here", "bbimport_ib3.php?action=cleanup"));
doformfooter("Send Emails");
}

if ($action == "dopasswords") {
if ($startat=="") {
$startat = 0;
}

$users = $DB_site->query("SELECT * FROM user WHERE importuserid <> '' LIMIT $startat,$perpage");
if ($DB_site->num_rows($users)) {

while ($user = $DB_site->fetch_array($users)) {

// make random number
mt_srand ((double) microtime() * 1000000);
$newpassword=mt_rand(0,100000000);

$DB_site->query("UPDATE user SET password='$newpassword' WHERE userid='$user[userid]'");
echo("User <i>$user[username]</i> updated...<br>");

$sendmessage = str_replace("\$username",$user[username],$emailmessage);
$sendmessage = str_replace("\$password",$newpassword,$emailmessage);

if ($reallysend == 1) {
mail($user[email], $emailsubject, $emailmessage, "From: \"$bbtitle Mailer\" <$webmasteremail>");
echo("Mail sent to <i>$user[username]</i>...<br><br>");
}
}
$startat+=$perpage;


doformheader("bbimport_ib3","dopasswords");
maketableheader("Update User Passwords");
makehiddenfields();
makehiddencode("emailmessage", $emailmessage);
makehiddencode("emailsubject", $emailsubject);
makehiddencode("startat", $startat);
makehiddencode("perpage", $perpage);
makehiddencode("reallysend", $reallysend);
doformfooter("Do Next Page",0);
} else {
makedescription("Password update complete.");
$action = "cleanup";
}
}

Logician
08-26-2002, 07:07 AM
1- Remove \ from \$username and \$password..

2- If this does not work insert
echo 'username='.$username.'<br>';
echo 'password='.$password.'<br>';

lines right after

if ($action == "passwords") {

and see if the variables are set correctly before being processed (if not you may need to "globalize" them)

3- Your message would well fit in "Help me Finish" or "PHP" boards rather than requests.. ;)