User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » PHP/MySQL question (complex, I think) Page [1]  
vertigo
Veteran
135 Posts
user info
edit post

I currently volunteer for a non-profit food kitchen-type organization where different organizations (whether religious or non-affiliated humanitarian groups) sign up for specific days to provide labor and foodstuff. This is a fairly large program and it works fairly well, though the sign-up process is a bit of a hassle. Currently, groups have to call in or send an email to a part-time volunteer secretary that has to manually record who will be there and on which days. I thought it would be a good idea and a relatively simple undertaking to set up an online form that will keep her from having to keep track of everyone. I know VERY basic PHP (like includes and some built-in functions) and, for some reason, though I could figure this out on my own. But I'm getting very frustrated and any help that you could provide would be much appreciated. This might be too much of a project and maybe I'm asking for too much, but I didn't think it would hurt to ask, especially since it's for a good cause. Really, any suggestions would be appreciated.

Okay, so there are 6 fields - date (preferably in yyyy-mm-dd format), first name of contact (20 characters max), last name of contact (25 characters max), email address (30 characters max), group ID number (4-digit number assigned by our organization to each individual group), and a phone number (preferably in the 123-456-7890 format). The HTML form (signup.html) looks like this:



<form id="signup" action="signup_form.php" method="post">
<ul>
<li><select name="date">
<option value="20080101">January 1, 2008</option>
<option value="20080102">January 2, 2008</option>
<option value="20080103">January 3, 2008</option>
</select></li>
<li>First Name: <input type="text" size="20" name="fname" /></li>
<li>Last Name: <input type="text" size="25" name="lname" /></li>
<li>Email: <input type="text" size="30" name="email" /></li>
<li>Group ID: <input type="text" size="4" name="group" /></li>
<li>Phone: <input type="text" size="12" name="phone" /></li>
<li><input class="button" type="submit" value="submit" /><input class="button" type="reset" value="reset" /></li>
</ul>
</form>



For each day, there are 3 sign-up spots (one for each meal) and an alternate in case a group has to cancel. Once the day is full, or after the date has passed, I'd love for the option to disappear from the list, but that might be more work than it's worth (I can manually add/remove these dates since it's not that time intensive and even I can handle it). After someone submits, I'd like for an email to be sent to the secretary that just lets her know that someone has signed up for a specific date. Also, I'd like the ability to print off the sheet for a single day, as well as the option to print off a full list (I mean, after all days are full, she'd be able to print off the full list and hang it on the bulletin board). Here's what I currently have for the database part (signup_form.php):



<?php

# connecting to MySQL database with default settings, storing as a variable #
# die is executed if the connection fails #
$fpDB = mysql_connect();
if (!$fpDB) {
die("Could not connect to database: " . mysql_error());
}

# creating the database, returning status #
if (mysql_query("CREATE DATABASE foodpantry_db",$fpDB)) {
echo "Database created.";
}
else {
echo "Error creating database: " . mysql_error();
}

# generating the table and fields within the database #
# setting primary key field, cannot be null #
mysql_select_db("foodpantry_db",$fpDB);
$sql = "CREATE TABLE group_signup (
foodpantry_dbID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(foodpantry_dbID),
VolDate date(yyyy-mm-dd),
FirstName varchar(20),
LastName varchar(25),
EmailAddy varchar(30),
GroupID int(4),
ContactNum varchar(12))";
mysql_query($sql,$fpDB);

# inserting values from form into the table #
$sql = "INSERT INTO group_signup (VolDate,FirstName,LastName,EmailAddy,GroupID,ContactNum)
VALUES('$_POST[date]','$_POST[fname]','$_POST[lname]','$_POST[email]','$_POST[group]','$_POST[phone]')";
if(!mysql_query($sql,$fpDB)) {
die("Error: " . mysql_error());
}
echo "1 record added.";

# closing the MySQL connection #
mysql_close($fpDB);

?>



For the emailing portion (which I've tried separately using just a form, with no database, and it works), I've got:



<?php

# begin output buffering to handle headers #
ob_start();

# prevents values from being entered in an URL #
if ($_SERVER['REQUEST_METHOD'] != "POST"){exit;}

# assign recipient email, subject, thank you and empty fields pages #
$sendto = 'myname@mysite.com';
$subject = 'Food Pantry Signup Form';
$thankyou = 'signup_reply.html';
$req_fields = 'req_fields.html';
$valid_email = 'valid_email.html';

# creates variables from form inputs #
$fname = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
$email = $_REQUEST['email'];
$group = $_REQUEST['group'];

# if the field contains data, compiles form variables into one - empty fields are omitted #
if (strcmp($fname, "")!=0) $body = $fname." ";
if (strcmp($lname, "")!=0) $body = $lname."\n";
if (strcmp($email, "")!=0) $body .= "Email: ".$email."\n";
if (strcmp($group, "")!=0) $body .= "Group ID: ".$group;

# assigns values to the email's header information (from, reply-to, etc.) #
$headers = "From: ".$email."\n";

# checks to make sure all fields are filled (all are required) #
if(empty($name) || empty($email) || empty($group)) {
header("location:$req_fields");
}

# checks to make sure there is a valid email address entered #
elseif((!$email == "") && (!strstr($email,"@") || !strstr($email,"."))) {
header("location:$valid_email");
}

# composes the email, redirects user to a thank you page after submission #
else {
mail($sendto, $subject, $body, $headers);
header("location:$thankyou");
}

# end output buffering #
ob_end_flush();

?>


I think maybe I'm asking for too much. It's just a lot more than I thought it would be, and I'm sort of piecing it together using various tutorials. I do have a server with MySQL to test it, but I know it's not complete. Again, any help you can provide would be appreciated. Even if your only suggestion is to get a professional to do it, I'd appreciate your viewpoint. Thanks!

[Edited on December 17, 2007 at 4:22 PM. Reason : I've pulled this from a number of different samples, so if something seems out of whack, let me know]

12/17/2007 4:18:40 PM

agentlion
All American
13936 Posts
user info
edit post

if you're not familiar enough with PHP/mySQL to write this, you shouldn't really be doing it from scratch yourself. find some libraries to do the heavy lifting for you, or a service like
http://www.dabbledb.com/

12/17/2007 4:38:17 PM

rynop
All American
829 Posts
user info
edit post

I dont have time to read your post right now, but you can always use a php framework (i use cakephp) to un-complicate things. In many cases if you setup your model relationships correctly, it will do the "heavy lifting" for you.

12/17/2007 4:44:20 PM

skokiaan
All American
26447 Posts
user info
edit post

This is one of those times where free help is too expensive.

12/18/2007 3:18:06 AM

Donogh5
All American
971 Posts
user info
edit post

this is pretty simple for someone with php/mysql experience, but it seems like you'd need to be taught the stuff rather than shown how to do it

you could always go the freelancer route: http://www.getafreelancer.com/

you can find relatively competent asian programmers on there for like 10 bucks a day

12/18/2007 6:19:27 AM

smc
All American
9221 Posts
user info
edit post

I can probably help you. Let me dig through my old code for a day or two.

12/18/2007 9:51:26 AM

Novicane
All American
15416 Posts
user info
edit post

instead of using a drop down box you could make them manually type in the date and then use a SQL query to determine if that date has passed or not using a if else type thing.

but i think it is possible to dynamically generate your drop down box.

12/18/2007 9:58:53 AM

Donogh5
All American
971 Posts
user info
edit post

yahoo offers a pretty decent calendar control for free: http://developer.yahoo.com/yui/calendar/

12/18/2007 10:03:00 AM

quagmire02
All American
44225 Posts
user info
edit post

wish i could help

12/18/2007 10:06:31 AM

vertigo
Veteran
135 Posts
user info
edit post

^^^^ If you have anything, that would be awesome...anything you've got would be appreciated.

I do appreciate all of the advice - I think this is a bit above my head, but this place has (literally) $0 extra cash, as they receive no state funding and operate completely through donations. If I can't figure it out or get something from there, I may just try the freelance option and donate money to it, instead.

12/18/2007 10:09:19 AM

30thAnnZ
Suspended
31803 Posts
user info
edit post

this is an extremely simple project. you should be able to wade through it with the help of any number of online resources.

it will be frustrating for a n00b, especially one without any other coding experience, but it is doable. it actually should be a good project to learn from if you do it yourself.

12/18/2007 11:59:06 AM

smc
All American
9221 Posts
user info
edit post

Here ya go:
http://dejaviews.org/checkout/meals

It needs better error checking, but tell me if that's in the ballpark.

[Edited on December 18, 2007 at 1:34 PM. Reason : There's sample data on Dec 19]

12/18/2007 1:33:50 PM

vertigo
Veteran
135 Posts
user info
edit post

^^ I know it's not complex for those with experience, and I do realize that while I don't want to rely on other people to TELL me how to do it, I learn much better when I can take something that already exists, break it apart, and SEE how it's constructed to better understand how it works. I'm a bit frustrated because I'm not entirely sure which functions and calls I should be using, and since I don't know them, I have a hard time finding the how-to's and tutorials online. Does that make sense? I'm not looking for someone to do it for me - first and foremost because I would like to learn how it's done so that I can expand upon it if the necessity arises. I understand your point, though.

^ Yes, that's almost exactly what I was envisioning! I didn't think of using a calendar as the date selection (though that does make more sense and I like it). Did you write that from scratch based on my outline or did you tweak an existing bit of code you had?

[Edited on December 18, 2007 at 2:25 PM. Reason : ^^]

12/18/2007 2:22:09 PM

smc
All American
9221 Posts
user info
edit post

I wrote it from scratch. Took about one and a half hours, but then again I'm rusty. That yahoo calendar really is nice. I also wrote a script that emails all the reservations to you in a list form(or you could use phpMyAdmin to view the database.

Do you have an email address I could send this code to? I'm sure you can handle it from here.

12/18/2007 3:38:08 PM

vertigo
Veteran
135 Posts
user info
edit post

Wow, I really appreciate the work you've done - I sent you a PM.

I'd like to give you credit for you've done, and your opinion on the finished product.

THANK YOU for your help!

12/18/2007 4:47:20 PM

 Message Boards » Tech Talk » PHP/MySQL question (complex, I think) Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.