Topic: Writing to database via a web form (Read 2988 times)
OMG!I am geek
Posts: 55
366 credits Members referred : 0
« on: Aug 29, 2006, 01:14:21 pm »
Hi Guys
I am a newbie so...but I can not find a decent tutorial on how to use a form to submit data to a MySQL table using PHP5. I tried several ways and got either duplicate records or records when the page was loaded or no data at all. Does the PHP go before or after the form data...I am using Olaf's access class as a basis and have connection to the DB but for some reason I can not get it to work.
For each user that has access to the webpages, do they need to have an account setup within MySQL? I know there are alot of questions here and have been reading quite alot, but none of the tutorials I found, seemed to work for me. Any suggestions on where I can find something that will work?
Thanks gman
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #1 on: Aug 29, 2006, 01:23:25 pm »
As I am not sure what Olaf's class do exactly, for start I will try to answer your general questions :
Quote
For each user that has access to the webpages, do they need to have an account setup within MySQL?
The user that connects to the database is php. So no matter how many users your site has, your users connect to the site, and the site connects to mysql with one account.
In general to react with the database you need a connection, and then everything is done with queries (SELECT, INSERT, UPDATE, etc.)
OMG!I am geek
Posts: 55
366 credits Members referred : 0
« Reply #6 on: Aug 29, 2006, 02:15:51 pm »
Thanks guys...have not looked at any of your responses but there are no issues with the database structure..that seems to be fine. What I would like is to just have a user form and add to the table what has been entered when the submit button is clicked. But I am writing to fields 2, 3 and 7 and not the others as they are auto incremented, so I am not sure if that has to be accounted for when doing the INSERT statement.
So let me read what you fine fellows have written and I am glad that I inspired you all
gman
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #7 on: Aug 29, 2006, 02:31:51 pm »
try a statement like this:
INSERT INTO table SET col1 = 'value 1', col7 = 'value7',....
this way you don't need to add values for all columns
OMG!I am geek
Posts: 55
366 credits Members referred : 0
« Reply #8 on: Aug 29, 2006, 03:29:20 pm »
Nikolas
I tried your example and assigned the variables for the $db_server..etc, but I am getting an error with the $query on the line starting with $res...also, O do not understand the $fields within your INSERT statement...what is this reading? The form names? Do they need to be defined outside the form? ie. $fields = 'field1', 'field2', 'field3'?
Thanks again gman
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #9 on: Aug 29, 2006, 03:59:27 pm »
To get this snippet work, you must make a post form that will send the data there.
For each <input> you must declare as name the name of the field in the table that you are about to insert the data.