Cappymoo;10989797 wrote:$fields{"$row[membertype]"} = "Member Type";
Just as an aside; PHP syntax is to use brackets [font=monospace][][/font] for array indices, not braces [font=monospace]{}[/font]. Hence
$fields[$row['membertype']] = "Member Type";
I tried reformatting your code to a more consistent style - the easier code is to read the easier it is to debug - (note the use of [noparse]
[/noparse] tags for PHP code):[code=php]<?php
// connect to the database
include('connect-db.php');
// get results from database
$result = mysql_query("SELECT id, membertype, lastname1, firstname1, email, date1, 'T1' AS users FROM users UNION select id, membertype, lastname1, firstname1, email, date1, 'Y1' AS youth from youth ORDER BY lastname1")
or die(mysql_error());
// display data in table
echo "<table border='1' cellpadding='10'>";
echo "<tr><th colspan=8>Membership Database - Reminders</th></tr>";
echo "<tr> <th>ID</th> <th>Member Type</th><th>Last Name</th> <th>First Name</th> <th>Date Submitted</th><th>Date Expires</th> <th>Email</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array($result))
{
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['membertype'] . '</td>';
echo '<td>' . $row['lastname1'] . '</td>';
echo '<td>' . $row['firstname1'] . '</td>';
echo '<td>' . $row['date1'] . '</td>';
$currentDate = $row['date1'];// current date
$regdate = $row['date1'];
$dateOneYearAdded = strtotime(date($regdate, strtotime($currentDate)) . " +1 year");
echo '<td>' .date('F dS Y', $dateOneYearAdded). ' </td>';
echo '<td>' . $row['email'] . '</td>';
$to = $row['email'];
$from = "xxxx@xxxx.com" ;
$name = $_REQUEST['lastname1'] ; // $name is never used
$headers = "From: $from"; // $headers is never used
$subject = "Membership Renewal Reminder";
$fields[$row["membertype"]] = "Member Type";
$fields["lastname1"] = "Last Name";
$fields["firstname1"] = "First Name";
$fields["regstudent"] = "School";
$fields["NewMember"] = "New Member";
$fields["ReturningMember"] = "Returning Member";
$fields["date1"] = "Date Submitted";
$body = "Your Membership is up for renewal:\n\n We have received the following information:\n\n";
foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}
$headers2 = "From: xxxx@xxxx.com"; // Not used
$subject2 = "Membership Renewal";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.xxxxx.org";
if($from == '')
{
print "You have not entered an email, please go back and try again";
}
else
{
$send = mail($from, $subject, $body);
$send2 = mail($to, $subject2, $autoreply, $body);
if($send)
{
print "";
}
else
{
print "We encountered an error sending your mail, please notify xxx@xxxx.org
..00000";
}
}
}
// close table>
echo "</table>";
?>
but I'm still too baffled by what it's doing to have a clear idea of what it is supposed to be doing with what. For example, these lines don't make a lot of sense:
$currentDate = $row['date1'];// current date
$regdate = $row['date1'];
$dateOneYearAdded = strtotime(date($regdate, strtotime($currentDate)) . " +1 year");
echo '<td>' .date('F dS Y', $dateOneYearAdded). ' </td>';
But I think the business with the $fields array could be written as
$body = "Your Membership is up for renewal:\n\n We have received the following information:\n\n";
// Some consistency in form field names wouldn't go amiss either...
$fields = array(
'Member Type' => $_REQUEST[$row['membertype']],
'Last Name' => $_REQUEST['lastname1'],
'First Name' => $_REQUEST['firstname1'],
'School' => $_REQUEST['regstudent'],
'New Member' => $_REQUEST['NewMember'],
'Returning Member' => $_REQUEST['ReturningMember'],
'Date Submitted' => $_REQUEST['date1'],
);
foreach($fields as $a => $b)
{
$body .= sprintf("%20s: %s\n", $a, $b);
}
There's
if($from == '')
{
print "You have not entered an email, please go back and try again";
}
Except $from is already known to have a value:
$from = "xxxx@xxxx.com" ;
And then there's this line:
$send2 = mail($to, $subject2, $autoreply, $body);
I'm not sure what you're trying to achieve here, but you probably don't want $body in it.