Forum Moderators: coopster
I have been using PHP solutions made easy by David Powers to 'brake the ice' on coding php, but now I've moved beyond what is given as example in the book and now I'm totally lost.
I'm trying to make a form were people can sign up and say they are coming to a class reunion. Well I have that part working, people can sign the form and it goes into a database, but the next part gets tricky, I need to have the names of the graduating class in the database for a later step where I will output who has responded and who hasn't so people can get in contact with each other.
I think the way to do this is start with all the names in the database then have the code check for a match on the first name and last name and if it finds a match for both, then it replaces the row in the database with new and updated information, including their indication of weather or not the are coming to the reunion.
So here is what I wrote. After adding the functions that check for the names and the switches, the code dose not seam to get passed the loop that checks for missing items.
function mailLetter() {
$to = "";
$subject = "Class Reunion: New Registration";
$message = "La Crosse Logan Class Reunion, New Registration: \n";
$message .= "Name : " . $_POST['first_name'] . "\n";
$message .= "Last Name : " . $_POST['last_name'] . "\n";
$message .= "Maiden Name : " . $_POST['maiden_name'] . "\n";
$message .= "Spouces Name : " . $_POST['spouses_name'] . "\n";
$message .= "Address : " . $_POST['address'] . "\n";
$message .= "Address 2 (Apt or Suite) : " . $_POST['apt_address'] . "\n";
$message .= "City : " . $_POST['city'] . "\n";
$message .= "State / Province / Territory: : " . $_POST['state'] . "\n";
$message .= "zip : " . $_POST['zip'] . "\n";
$message .= "Phone Number : " . $_POST['phone_number'] . "\n";
$message .= "E-mail : " . $_POST['e_mail'] . "\n";
$message .= "Will you attend? : " . $_POST['attend'] . "\n";
$from= "From: {$_POST['e_mail']}\n";
if(mail($to, $subject, $message, $from)) {
unset($missing);
header('Location: thanks.php');
exit;
}
else {
header('Location: sorry.php');
}
}
function checkFirstname () {
$lookatFirst = "SELECT alumni_id FROM alumni
WHERE first_name = '$first_name'";
$firstResult = mysql_query($lookatFirst) or die(mysql_error());
$first = mysql_num_rows($firstResult);
if ($first>0) {
$first = 1;
array_push($checkDuplicate, $first);
}
}
function checkLastname () {
if ($first>0) {
$checkLast = "SELECT alumni_id FROM alumni
WHERE last_name = '$last_name'";
$lastResult = mysql_query($checkLast) or die(mysql_error());
$last = mysql_num_rows($lastResult);
if ($last>0) {
$last = 2;
array_push($checkDuplicate, $last);
}
}
}
if (array_key_exists('sign', $_POST)) {
$expected = array ('first_name','last_name','maiden_name','spouses_name','address','apt_address',
'city','state','zip','phone_number','e_mail','attend');
$required = array('first_name','last_name','address','city','state','zip','e_mail','attend');
$missing = array();
foreach ($_POST as $key => $value) {
$temp = is_array($value) ? $value : trim($value);
if (empty($temp) && in_array($key, $required)) {
array_push($missing, $key);
}
elseif (in_array($key, $expected)) {
${$key} = $temp;
}
}
if (empty($missing)) {
$checkDuplicate = array();
checkFirstname ();
checkLastname ();
$foundItems = explode(" ", $checkDuplicate);
switch ($foundItems) {
case 0:
// insert details into database
$sqlguests = "INSERT INTO alumni (first_name,last_name,maiden_name,spouses_name,address,
apt_address,city,state,zip,phone_number,e_mail,attend)
VALUES ('$first_name','$last_name','$maiden_name','$spouses_name','$address',
'$apt_address','$city','$state','$zip','$phone_number','$e_mail','$attend')";
$resultsqlguests = mysql_query($sqlguests) or die(mysql_error());
if ($resultsqlguests) {
mailLetter();
}
break;
case 2:
$updateguest = "REPLACE INTO alumni (first_name,last_name,maiden_name,spouses_name,address,
apt_address,city,state,zip,phone_number,e_mail,attend)
VALUES ('$first_name','$last_name','$maiden_name','$spouses_name','$address',
'$apt_address','$city','$state','$zip','$phone_number','$e_mail','$attend')";
$resultsUpdateguest = mysql_query($updateguest) or die(mysql_error());
if ($resultsUpdateguest) {
mailLetter();
}
break;
}
}
}
[edited by: coopster at 5:50 pm (utc) on April 10, 2009]
[edit reason] fixed sidescroll [/edit]
I think the way to do this is start with all the names in the database then have the code check for a match on the first name and last name
It's better design to have a unique ID assigned to each entry. Besides the above issue with duplicate data (that isn't really duplicate, since the 2 Mike Smiths are 2 different people), numeric lookups are faster than text searches (not a major problem if your table is small, but definitely becomes more of an issue as you grow).
But in the interest of figuring out how to do this so the form can be reused how do I go about creating the output forms? One form is going to list all the people who have not registured, and the other will list who has. How do I remove a name with a unique ID key from the 'has not responded' table when people anonomusly register?
The constraints for this project would be:
1. The orginizer dosen't want people to have to register with a user name and password before they can RSVP
2. We don't have everyone's e-mail address or complete mailing address, so we can't send out e-mails and have everyone respond via e-mail id.
Not sure how to do this without manually changing things.
how do I go about creating the output forms? One form is going to list all the people who have not registured, and the other will list who has.
How do I remove a name with a unique ID key from the 'has not responded' table when people anonomusly register?
Well, given the constraints, I guess you'll have to lookup by first/last name. So basically anyone can go to the site, find a name, pretend to be that person, and say that person will attend (or not attend)?
That's sort of like having a signup form to get on an e-mail list, but not requiring their e-mail address. :)
Yes realize this, but I'm not sure how else to do the form since I don't have everyone's e-mail (can't send them a verification link)..
I have some other idea's to try out, I'll see if I get stumped again.