forms help. best way to do this.

Joined
12 Feb 2006
Posts
17,644
Location
Surrey
im making a dummy website atm to learn so new stuff. please bear (sp?) with me as i am really struggling on how to word it :( so this may come out really bad.

i have the layout all sorted its the content parts that are being a pain in the back side. I have set up user accounts and admin accounts in php and mysql which is all fine. What im struggling with now is the forms.

what i want to do is have it so that if someone submits something on the form it will either be sent to me for processing and then pbulisehd by me, or if they are a user it will be displayed on the current page with the username showing. now I need help with the whole process of how i'd do this.

i have atm php check if the person if signed in or not, and if they aren't it displays one form that will email itself to me, and if they are there is the same form that when set up will submit itself to a table and then the page will load the information just like with a comment system.

1. how would i get a form to submit itself to a table along with what user submitted it?
2. how then would i get php to read whats on the table and then display it on the page in a specific way e.g. have it so that the username is h2 in green, the desicription of the user is normal size black writting underneath the username, then the email address for the user to be displayed under that in red.

I'm thinking that this will need to be on 3 serpate pages

alternatively does anyone know of any good forms tutorials and exmaples that i could look at so see how they are done? i have looked at a few on a tutorial website and google some but they are all for a comments system and don't work how'd id like them to.

like i said sorry about the bad wording, im really confused about what im donig here. If a reworded post is needed i can try?
 
Last edited:
What you're basically asking is how to write to a record to database and then read it back and display it as html - this is the very essence of most MySql + PHP tutorials, there should be plenty on the net, haven't got a link to a particular good one at the minute but someone will have. Personally I'd buy a MySql + PHP book, such as one of the following: ISBN-13: 978-0975240212 / ISBN-13: 978-0672326721 / ISBN-13: 978-0321336576, they're all around £20-30 and it's definitely worth having one handy.

Anyways, here's a quick summation of what you need to do without the details:

1. The form passes the submitted values to your form handler (which will be a php script) in the form of POST or GET variables.
2. The PHP script clenses the input, opens a database connection, inserts the record, and closes the connection (and then optionally shows a confirmation or just redirects to the next bit).
3. A second PHP script (your view page) opens a DB connection, retrieves the record (usually as an array but this is up to you), and then outputs the values using the specified html formatting.

All of the above is covered in numerous tutorials all over the net, but books are generally (not always!) better written and easier to follow.
 
Back
Top Bottom