Hi here is a script that i am writing for the local Lions Club Districts. It's to replace their existing carbon copy based form with this automated form. The link to the form is http://www.tacit-design.com/district14e/form.html
Now when this is filled out, it is supposed to choose email addresses from a MySQL Database depending on the <select> box value, and then email the form to those email addresses. But as you will see it doesn't work, and when i try to display the data i get Resourse ID # errors.
here is the PHP script that the form vars are POSTed to:
<?php
session_start();
foreach($_POST as $varname => $value)
$formVars[$varname] = $value;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>District 14e District Level Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$message = ""; /* TOO Long to POST, simple HTML of FORM PAGE that echo's $formVars instead of form objects; slashes are placed where needed */
// Open Email Database and pull out email addresses
$connection = @ mysql_pconnect($hostName, $username, $password) or die(mysql_error());
$db = mysql_select_db($databaseName, $connection) or die(mysql_error());
// Decide who to send the form to.
if ($formVars['region'] == 'r1z1'){
$region_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (1) AND zone = (0)");
$zone_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (1) AND zone = (1)");
$region_row = mysql_fetch_field($region_sql);
$zone_row = mysql_fetch_field($zone_sql);
$email_region = $region_row['email'];
$email_zone = $zone_row['email'];
}elseif ($formVars['region'] == 'r1z2'){
$region_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (1) AND zone = (0)");
$zone_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (1) AND zone = (2)");
$region_row = mysql_fetch_field($region_sql);
$zone_row = mysql_fetch_field($zone_sql);
$email_region = $region_row['email'];
$email_zone = $zone_row['email'];
}elseif ($formVars['region'] == 'r2z1'){
$region_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (2) AND zone = (0)");
$zone_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (2) AND zone = (1)");
$region_row = mysql_fetch_field($region_sql);
$zone_row = mysql_fetch_field($zone_sql);
$email_region = $region_row['email'];
$email_zone = $zone_row['email'];
}elseif ($formVars['region'] == 'r2z2'){
$region_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (2) AND zone = (0)");
$zone_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (2) AND zone = (2)");
$region_row = mysql_fetch_field($region_sql);
$zone_row = mysql_fetch_field($zone_sql);
$email_region = $region_row['email'];
$email_zone = $zone_row['email'];
}elseif ($formVars['region'] == 'r3z1'){
$region_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (3) AND zone = (0)");
$zone_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (3) AND zone = (1)");
$region_row = mysql_fetch_field($region_sql);
$zone_row = mysql_fetch_field($zone_sql);
$email_region = $region_row['email'];
$email_zone = $zone_row['email'];
}elseif ($formVars['region'] == 'r3z2'){
$region_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (3) AND zone = (0)");
$zone_sql = mysql_query("SELECT email FROM lionsemail WHERE region = (3) AND zone = (2)");
$region_row = mysql_fetch_field($region_sql);
$zone_row = mysql_fetch_field($zone_sql);
$email_region = $region_row['email'];
$email_zone = $zone_row['email'];
}
$vice_governor = mysql_query("SELECT email FROM lionsemail WHERE region = (4) AND zone = (0)"); // Vice District Governor
$governor = mysql_query("SELECT email FROM lionsemail WHERE region = (5) AND zone = (0)"); // District Governor
if ($governor == "none"){
echo "Unfortunaley, your district governor does not have an email address, you will have to send them a hard copy of this form. Please print the form below";
echo "<p>". stripslashes($message) . "</p>";
}elseif($vice_governor == "none"){
echo "Unfortunaley, your vice district governor does not have an email address, you will have to send them a hard copy of this form. Please print the form below";
echo "<p>". stripslashes($message) . "</p>";
}elseif($email_region == "none"){
echo "Unfortunaley, your region chairperson does not have an email address, you will have to send them a hard copy of this form. Please print the form below";
echo "<p>". stripslashes($message) . "</p>";
}elseif($email_zone == "none"){
echo "Unfortunaley, your zone chairperson does not have an email address, you will have to send them a hard copy of this form. Please print the form below";
echo "<p>". stripslashes($message) . "</p>";
}
echo "Gov: $governor <br> V: $vice_governor <br> R: $email_region <br> Z: $email_zone <br>";
$eaddy = "$governor, $vice_governor, $email_region, $email_zone";
$subject = "*! District 14e Report !*";
mail($eaddy, $subject, $message);
echo "The form has successfully been sent to: <br>
District Governor: $governor <br>
Vice District Governor: $vice_governor <br>
Region Chairperson: $email_region <br>
Zone Chairperson: $email_zone <br> ";
?>
</body>
</html>
If you go to the form and just click the submit botton you will see the errors that i am getting. I have not added any input error checking, the only field that matters is the <select> box for choosing the region and zone
I would really appreciate any help. Thank-you!