Form Processing
Moderator: General Moderators
Form Processing
Hi All,
Can someone point me in the direction to find help (tutorial or some code) in creating a php code. I have a form with First name, last name, phone, email, address, city, state, zip, and comments. I would like all the info emailed to an email address (the easy part, already done) and also write everything except the comments to a MYSQL database.
As I said, I have completed the first part using ezformmail, but I want to write the data. I have written data to database before, but I have never combine the two. If I can't use ezformmail and have to create a new php script, I will need it validate the fields before sending.
Can someone point me in the direction to find help (tutorial or some code) in creating a php code. I have a form with First name, last name, phone, email, address, city, state, zip, and comments. I would like all the info emailed to an email address (the easy part, already done) and also write everything except the comments to a MYSQL database.
As I said, I have completed the first part using ezformmail, but I want to write the data. I have written data to database before, but I have never combine the two. If I can't use ezformmail and have to create a new php script, I will need it validate the fields before sending.
- MrPotatoes
- Forum Regular
- Posts: 617
- Joined: Wed May 24, 2006 6:42 am
if you are new reinvent the wheel otherwise you'll learn nothing. and when you reinvent the wheel make sure to put in errors where you expect them to happen and understand why.
otherwise if you know what you are doing, and i mean intermediate not still green, feel free to use libraries. if you want to start from scratch. no biggie.
personally i'm writing a CMS from scratch and in 2 weeks (off time mostly) i've gotten everything in there that i need currently. DB interaction, simple insecur user auth (just testing purposes), templating, all all other kinds of neet stuff but i'm using a whole bunch of free open source(BSD/Apache/Mozzilla licence) code. good times
but like i said, if you are starting out take it from me that you better reinvent the wheel if you expect to get anything done. because if something goes wrong later down the road you are not going to know wher the problem is and you'll be screwed lmao. that sucks worse than knowing what you are doing. what could be a simple fix for someone that knows what they are doing could be an eternity of code if they don't
cheers
otherwise if you know what you are doing, and i mean intermediate not still green, feel free to use libraries. if you want to start from scratch. no biggie.
personally i'm writing a CMS from scratch and in 2 weeks (off time mostly) i've gotten everything in there that i need currently. DB interaction, simple insecur user auth (just testing purposes), templating, all all other kinds of neet stuff but i'm using a whole bunch of free open source(BSD/Apache/Mozzilla licence) code. good times
but like i said, if you are starting out take it from me that you better reinvent the wheel if you expect to get anything done. because if something goes wrong later down the road you are not going to know wher the problem is and you'll be screwed lmao. that sucks worse than knowing what you are doing. what could be a simple fix for someone that knows what they are doing could be an eternity of code if they don't
cheers
I'm of exactly the opposite opinion.bokehman wrote:You are better of writing your own stuff. Most stuff available seems to be very bulky, often doesn't work at all or has terrble logic or security, or needs lots of customisation to fit your requirements.
Lets take mail for example. Most people writing a mailing library won't be aware of all the intricate issues present in RFC's, all the issues with security and injection, and more. Whereas a project (Like Swift mailer, or PHPMailer), are focused on only that one problem. As a result, they've looked at the RFC's. They've dealt with the security issues.
People don't build cars themselves and drive them on the roads (often), because its (generally) not safe enough.
Having a specialist focus on a specific field (library) means more security, better design, and more focus on the issues there.
Personally, I think someone coding their own solution (when specialist libraries are available) is incredibly arrogant. Its saying that they are better than the 2+ years, and dozens of contributors that have worked on an established, well-respected library.
Don't get me wrong, there are certainly exceptions to the rule. Swift mailer definitely comes to mind. But even in that project, its not a "I'm gonna build my own for my stuff" issue, its a full-out competitor to phpmailer - including asking for community contributions.
There is little advantage to writing your own libraries, and substantial risks in doing so in security, flexibility, and more.
Personally I've built cars for both the street and the drag strip but I know where you are coming from. PhpMailer is a particularly well written example but for every excellent piece of code offered there are 100 terrible ones, for example, in my opinion, a lot of the offerings from that dynamic HTML site.Roja wrote:I'm of exactly the opposite opinion... don't build cars themselves...
I can see both sides of the argument, but I'm on the "Write your own" side.
1) You gain experience in writing code from scratch
2) It does exactly what you want it to do, with no extra
3) If you need to change it afterwards, it's your code, you wrote it, it is much easier to change bits of it without risking breaking something else.
4) Once you've built up enough libraries of functions, you know how they work together, which makes for quicker development, and quicker troubleshooting too
From a basic "pride" point of view, I like to be able to look at a finished program, and think "I wrote that".
"I copied and pasted that, and altered a few bits" just doesn't have the same ring to it
1) You gain experience in writing code from scratch
2) It does exactly what you want it to do, with no extra
3) If you need to change it afterwards, it's your code, you wrote it, it is much easier to change bits of it without risking breaking something else.
4) Once you've built up enough libraries of functions, you know how they work together, which makes for quicker development, and quicker troubleshooting too
From a basic "pride" point of view, I like to be able to look at a finished program, and think "I wrote that".
"I copied and pasted that, and altered a few bits" just doesn't have the same ring to it
A lot of people choose to code their own solution for reasons more along the lines of learning and for testing themselves. There are plenty of DB wrapper classes, templating engines, etc etc, but I choose to write my own for the mere fact that later on I can say I wrote all of it on my own, and because it keeps me on my toes for coding practice. I do not claim to be better than anyone who chooses to group together and create some form of a library. I commend them on providing easily accessible solutions to those who want them.Roja wrote:Personally, I think someone coding their own solution (when specialist libraries are available) is incredibly arrogant. Its saying that they are better than the 2+ years, and dozens of contributors that have worked on an established, well-respected library.
There is little advantage to writing your own libraries, and substantial risks in doing so in security, flexibility, and more.
In terms of litte advantage, I would consider the fact that to write your own library forces you to learn things you wouldn't have if you used an existing one, that's a huge advantage. Efficiency, flexibility, modularity, and security are risks, yes, but part of that learning process is learning of these risks, and then fixing them.
But do you?GM wrote:1) You gain experience in writing code from scratch
If you practice swinging a thousand times a day, but are practicing it incorrectly, you are learning bad habits - not good habits.
Similarly, if someone codes a solution that isn't as well designed as a well-established library, they are 'gaining experience' in how to code an inferior solution. Worse, as many here are showing, they walk away feeling like they've done BETTER than someone using an established library.
But does it?GM wrote:2) It does exactly what you want it to do, with no extra
If it isn't RFC compliant, is it really doing mail the way you want it to? If it gets your app, and your server compromised, because you didn't know you needed to filter the headers included on mail, is it doing EXACTLY what you want?
"No extra" is absolutely pointing to "Premature optimization". What you may be trimming as "fat" is the security, stability, and testing that makes it "slower". Worse, you might not even have a performance concern at all - so you are sacrificing something important (needed functionality) for a worthless improvement in speed or memory use that didn't impact you at all.
Is it?GM wrote:3) If you need to change it afterwards, it's your code, you wrote it, it is much easier to change bits of it without risking breaking something else.
With a community of people experienced in that library, you gain their knowledge and experience, and their guidance in understanding why you can't "just pass the headers on without filtering them" (to save some performance hits). Doing it on your own means you have to know that. You have to research that. You have to understand how to change your code to do that. All on your own. See where the arrogance sets in?
Ah, but you have to troubleshoot not only your app, but also your libaries. Whereas a library that does what it says it does (phpmailer for example), you don't have to spend the time developing and troubleshooting it. If in fact you do find an error, you may be able to get someone ELSE to fix the bug just by reporting it! Free bug fixes for zero effort v. debugging code you wrote (which probably doesn't follow RFC). I think thats an obvious win for people not reinventing the wheel.GM wrote:4) Once you've built up enough libraries of functions, you know how they work together, which makes for quicker development, and quicker troubleshooting too
From a pride point of view, I like to say "I spent my time on my app, and it has 20 hours more development in it because I used an established library instead of rolling my own". Take pride in improving your program, not the underlying libraries used to send mail or access a database.GM wrote:From a basic "pride" point of view, I like to be able to look at a finished program, and think "I wrote that".
I contributed improvements to a dozen opensource projects used by millions of people worldwide has quite a different ring than "I coded a neato mail sending library that I use".GM wrote:"I copied and pasted that, and altered a few bits" just doesn't have the same ring to it
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Writing most of your own stuff is not a bad idea at any rate.
When I started, and looked at other peoples software, it confused the hell out of me. Now, when I want to know how something is done, I look through other peoples software and see how they do it.
When you first start, you should probably write as much of your own code as you can. I would say that it also depends on what you are doing.
If you are doing a job for someone, you may want to use already written libraries. After all, your client doesn't want to wait 4 weeks for the ultra website that he's been dreaming of.
I write all of my own code, most of the time. If I am stumped on a job and time is running short, I use a library. For my personal website though, I write all of my own code, everytime. It's my playground where I test new ideas and practice and I think that everyone should have a place for that.
Athletes don't improve by not practicing.
When I started, and looked at other peoples software, it confused the hell out of me. Now, when I want to know how something is done, I look through other peoples software and see how they do it.
When you first start, you should probably write as much of your own code as you can. I would say that it also depends on what you are doing.
If you are doing a job for someone, you may want to use already written libraries. After all, your client doesn't want to wait 4 weeks for the ultra website that he's been dreaming of.
I write all of my own code, most of the time. If I am stumped on a job and time is running short, I use a library. For my personal website though, I write all of my own code, everytime. It's my playground where I test new ideas and practice and I think that everyone should have a place for that.
Athletes don't improve by not practicing.
As I said, I can agree with both points of view, and the points you have made are very valid. In reference to the email class, I freely admit that I don't have the faintest idea of all the stuff I need to do to correctly send an email. However, I would never, ever consider writing my own code that does it! First, I would pull to pieces code that is already written - like phpmailer - for example, to see how it works, what it does, and why. I'd also read internet forums, articles, tutorials on email, and only then would I consider myself in a position to even begin writing something that sends an email. (Note, I'm not under any time constraints - I program in my spare time).Roja wrote:Lots of good points
In terms of doing other things - database connections, session handlers, for example I like to write my own. I know what kind of database I want to connect to, I don't imagine that in some future I'm going to change databases, and if I do, I'll edit it then. I'd rather not spend time writing code that will connect me to any conceivable database if the chances are I'm NEVER going to connect to them.
I guess one of the fundamental points here is that you perhaps are looking at this topic from the point of view of a professional, whereas I'm looking at it from the point of view of an enthusiastic amateur. If ever I become a professional, where applications I create/work on need to be secure and portable, then I'd agree that something worked on by hundreds of people is bound to be better than what I could produce, but for now, I'm happy with what I produce - it's secure, it's portable enough, and it does what I need it to do. I come here for best practices, I read a lot of tutorials, and I have a background as a professional programmer, so I know what it means to write clean, reusable code. I'm reasonably confident that my code is as good as many of the tutorials that can be found on the internet.
Replacing well-established libraries by coding your own based on advice here isn't like having hundreds of coaches.GM wrote:...and that's why we come here - it's like having hundreds of coaches.feyd wrote:But any good athlete has a coach that shows them how to practice.Daedalus- wrote:Athletes don't improve by not practicing.
Its like blindfolding yourself, walking through a minefield, and asking people to shout if you are going to step on a landmine.
Hardly as effective, or as intelligent. But hey, you might not step on the same landmine twice.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
I don't think that making a mistake is your scripting is quite as severe as stepping on a land-mine.
I, myself, prefer to step on the land-mines to make sure I never hit the same one twice, but that is just me.
I, myself, prefer to step on the land-mines to make sure I never hit the same one twice, but that is just me.
Aye.feyd wrote:But any good athlete has a coach that shows them how to practice.Daedalus- wrote:Athletes don't improve by not practicing.
- MrPotatoes
- Forum Regular
- Posts: 617
- Joined: Wed May 24, 2006 6:42 am
whoa whoa whoa whoa whoa there buddy.Roja wrote:Personally, I think someone coding their own solution (when specialist libraries are available) is incredibly arrogant. Its saying that they are better than the 2+ years, and dozens of contributors that have worked on an established, well-respected library.
so i guess i'm arrogant because i'm building my own framework because there are hundreds out there already? why build house when there is one that is already built. what if it was the lead developer to the PHPMailer and he wanted to make another one? he shouldn't because it's already there?
why write a book if there are some out there already? this is the most illogical reasoning i've ever heard
there are SO many reasons to do something and they don't have to be completely justifiable
i'll list you the reasons i'm doing what i'm doing
0. it's not up to snuff
1. it's got all kinds of things you DO NOT need
2. doesn't support features you want, need or just plain lust
3. you want to learn from it
4. you want something propretary because you plan to build a company off of it. so using certain open source libraries isn't the right thing to do if you plan to go this commerical route
5. you love to code and nothing makes you happier than learning something new
6. explore your horizons in coding and coding patterns
7. it's incredibly bloated. what if i don't need half the functions of whatever giant library is out there? then you get stuck having those in there and in memory because if you remove it you run the risk of completely destroying something else.
8. speed
9. for fun
there. 10 reasons to support making your own anything and this goes for anything you want to build yourself (car, house, company, software, music, etc).