pcw Posted March 16, 2011 Share Posted March 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/230842-script-not-working/ Share on other sites More sharing options...
arbitter Posted March 16, 2011 Share Posted March 16, 2011 Not sure about this, but when writing your PHP funciton: function decode_variable(&$siteName) I think that ampersand is not needed? I could be mistaken, I've never used any php functions. Quote Link to comment https://forums.phpfreaks.com/topic/230842-script-not-working/#findComment-1188352 Share on other sites More sharing options...
pcw Posted March 16, 2011 Author Share Posted March 16, 2011 hi arbitter the & is meant to be there and functions fine. The only problem is for some reason the email is not sending Quote Link to comment https://forums.phpfreaks.com/topic/230842-script-not-working/#findComment-1188354 Share on other sites More sharing options...
arbitter Posted March 16, 2011 Share Posted March 16, 2011 Second attempt: Shouldn't <?php while($info = mysql_fetch_array( $data )) { $email = $data['email']; $username = $data['username']; $firstname = $data['firstname']; $password = $data['password']; } ?> Be $email = $info['email']; ... and so on Quote Link to comment https://forums.phpfreaks.com/topic/230842-script-not-working/#findComment-1188356 Share on other sites More sharing options...
KevinM1 Posted March 16, 2011 Share Posted March 16, 2011 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) Quote Link to comment https://forums.phpfreaks.com/topic/230842-script-not-working/#findComment-1188357 Share on other sites More sharing options...
pcw Posted March 16, 2011 Author Share Posted March 16, 2011 Thankyou to both of you, I overlooked the $data $info issue. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/230842-script-not-working/#findComment-1188359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.