Jump to content

Recommended Posts

Hi, First of all, this is not a mysql error

 

I got the following script which updates a mysql field before redirecting the script to another "page" to get the users information from the database and then sending an email to notify the user that their account has been approved.

 

However, the message isnt sent and the Approval Message Failed message is displayed.

 

Here are both parts of the script although it is the second part which is failing.

 

case "approval":

include_once("data/mysql.php");

$mysqlPassword = (base64_decode($mysqlpword));

$username = $_GET['username'];

$db = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die ("Error connecting to database");

mysql_select_db("$dbname", $db) or die ("An error occured when connecting to database");

mysql_query("UPDATE members SET approved = 'yes'
WHERE username = '$username'");

mysql_close($db);

header("Location: admin.php?cmd=appMailSend&username=$username");

break;

 

Part 2

 

case "appMailSend":

include_once("data/mysql.php");
include_once("data/server.php");

$username = $_GET['username'];

function decode_variable(&$siteName)
{
    $siteName = urldecode($siteName);
    $siteName = str_replace('%20',' ',$siteName); 
    return $siteName;
} 

decode_variable($siteName);

$mysqlPassword = (base64_decode($mysqlpword));

$db = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die ("Error connecting to database");

mysql_select_db("$dbname", $db) or die ("An error occured when connecting to database");

$data = mysql_query("SELECT * FROM members WHERE username='$username'") 
or die(mysql_error()); 
while($info = mysql_fetch_array( $data )) 
{ 
$email = $data['email'];
$username = $data['username'];
$firstname = $data['firstname'];
$password = $data['password'];
}
mysql_close($db);

// Send Approval email

$bodyApp = file_get_contents('data/approvalMail.php');

$to = "$email";
$subject = "Welcome to $siteName";
$body = "\nDear $firstname;\n$bodyApp\nUsername: $username';\n Password: $password;";
if (mail($to, $subject, $body)) {
   
// Redirect back to manage page
header("Location: admin.php?cmd=manage1");


} else {

echo "Approval Message Failed";

}

break;

 

As always, any help is much appreciated.

 

Paul

Link to comment
https://forums.phpfreaks.com/topic/230842-script-not-working/
Share on other sites

The '&' denotes an argument being passed in by reference.

 

The problem is in your while-loop.  You want $info['email'], not $data['email'], and the same goes for all the rest.  Also, you never store the return value generated by decode_variable.  You need:

 

$var = decode_variable($sitename);

 

(obviously rename $var to something more meaningful)

Link to comment
https://forums.phpfreaks.com/topic/230842-script-not-working/#findComment-1188357
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.