Getting data from msql tables and emailing the result
Below is a bit of code that I'm wanting to gather some data from a couple of msql tables and email them to a user. (It's to remind user of their username and password in a low security situation - They have submitted their email address)
I've pasted some elements together from other pages, in the hope that it will do what I want.
At present it fails with the message
"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 's Test'' at line 1", having displayed $org as requested (as a test)
I'd be grateful if anyone can debug this problem, or otherwise advise.
<?php require_once('../../Connections/tormented3.php'); ?>
<?php
//now the recordset to link email-address to organisaton
$colname_rstSix = "1";
if (isset($_GET['email'])) {
$colname_rstSix = (get_magic_quotes_gpc()) ? $_GET['email'] : addslashes($_GET['email']);
}
mysql_select_db($database_tormented3, $tormented3);
$query_rstSix = sprintf("SELECT ck_organisation FROM chk_sixmonth WHERE ck_email = '%s'", $colname_rstSix);
$rstSix = mysql_query($query_rstSix, $tormented3) or die(mysql_error());
$row_rstSix = mysql_fetch_assoc($rstSix);
$totalRows_rstSix = mysql_num_rows($rstSix);
//end recordset
$org = $row_rstSix['ck_organisation'];
echo $org; //temporary test. Yes, it does send correct text to monitor
//now recordset to link organisation to access details
mysql_select_db($database_tormented3, $tormented3);
$query_rstPword = sprintf("SELECT organisation, username, password FROM passwords WHERE organisation = '%s'", $org);
$rstPword = mysql_query($query_rstPword, $tormented3) or die(mysql_error());
$row_rstPword = mysql_fetch_assoc($rstPword);
$totalRows_rstPword = mysql_num_rows($rstPword);
//start emailing routine
$start = "Your Access Information for updating the Torbay Mental Health website.
Your Username is\n";// Set up the email message header
$username = $row_rstSix['username'];
$pword = $row_rstSix['password'];
$message .= "$start $username . Your Password is $pword\n Thank you for updating your entries.";
if ( mail( $email, 'Access information reminder',
$message, "From: feedback@sample.org.uk \r\n")){
header('location:http://www.sample.org.uk');// redirect to page if email has been successfully sent
exit;
}else{
$error == '<p style="color:red;">An error occured, your email could not be sent. Please try again</p>';
}
?>
Many thanks.
