Forum Moderators: coopster

Message Too Old, No Replies

sending form results to a database

         

surrealillusions

5:47 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



How do you send form results to a database?

I'm trying to create my own guestbook/comment type script.

But as i've never done this before..i dont know how to do it.

I'm guessing - user fills out form, that talks to the database, 'hello mr database, i'm some form info, where would you like me to sit?'

At a rough guess, you need to specify the database, username and password, but how do you do this and write to the database?

Is it best to setup the database already with the tables already created? As i can do that via myphpadmin.

Next step is to speak to the database about publishing the results..but i want to get this first bit done first.

:)

piznac

6:47 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Yes its better to have your db already setup. 1st you will need a connection script (I would suggest you do this in a seperate file and include it). Then you will use the "INSERT INTO" sql statement to insert it into the db. There are tons of good tutorials across the web to help you get started. Remember to include some security as guestbooks and such are favorite marks for spammers,...

surrealillusions

8:05 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



ok..thanks.

I presume the tables in the database reflect the form fields? Like name, comments, email etc..

How would you inplement a captcha system into this? Any good tutorials anywhere?

thanks

:)

piznac

11:58 pm on Jan 8, 2008 (gmt 0)

10+ Year Member



Yeah you can do it that way. Database is all about logic,.. but for something like a guestbook you can do it very simple. And yeah there are some great captcha tutorials out there. The basic concept is to use a rand number (and letters) generated by php, save this to a variable, then use imagemagick or the gd libary to make them images. Then when submited compare it to your variable.

piznac

12:00 am on Jan 9, 2008 (gmt 0)

10+ Year Member



And since I cant figure out how to edit a post,.. I'll double post.

You need to think about input security as well. SQL injection is bad news,.. so remember that when working on this. A few php functions will keep you in the clear,.. or as in the clear as you can get.