Absolute beginner needs help setting up HTML form to database connection
2013-01-12 1:25 pm
I've set up a database table in phpMyAdmin, and have copied and pasted the code below (from a website that I found) into my own HTML file.
I'd like to learn what I need to do to connect this HTML to the "username_myTable" database table that I set up.
The database table has the following columns: firstname, lastname, email, phone, and comment.
My ultimate goal is to be able to collect visitor's information from my website so that I can do email marketing campaigns using the data that would get stored in the database.
Let me know if I should include more information. Any help would be greatly appreciated.
You will receive our response
with a few minutes
2013-01-13 6:58 am
Unfortunately I'm not seeing any code that your pasted so I'm unable to directly follow along with what you're trying to accomplish with the code.
We do have an article on using PHP to insert data into a MySQL database that you might find handy.
It sounds like you'd want to setup <input> tags for your various fields in your HTML form first. As an example lets say you used something like:
Then in your PHP script you'd want to grab these values that are getting sent via a POST request, with something like:
Then build up a SQL query to insert the data into your database in a table called comments with something like:
Also if your end goal is for email marketing campaigns, you might be interested in skipping doing this manually into your own database. We have a phpList education channel that I'm actually in the process of putting the final touches on. For a quick glance at what I'm talking about, the relevant section of that channel for you would be how to create a subscribe page in phpList.
Basically phpList is about the most popular open source mailing list manager on the web, and it supports setting up subscription pages that users can come to on your site. You can specify certain attributes that they must include when signing up for a mailing list, such as their name and phone number, and then it even handles sending them a confirmation email to confirm their interest in your mailings (referred to as opt-in which is required by our terms of service).
Hope some of this information gets you pointed in the right direction. If you have any further questions at all please let us know!