html form connect to mysql database

hello there, i am a novice in web development program and still got lot of things to learn.Im having a problem with the connection between html form and mysql.as far as i know, we need to link html form to a php code($_POST).but what really wonders me is, where should i put the mysql_connection in?is it in the same file as i put the $_POST or what? and i don't really get it about adding a new row into MySQL.i do know that i can use the

$sql="INSECT INTO mydb(name,age)

Values('farhan', 21)what wonders me is, how to make it more interactive?meaning to say, when user submit the form that has been filled in by pressing the submit button, the form then will be in the first row,followed with the second one with respective row and so forth.from what i've learned, the form will be sent to a file that contain $_POST but how will it be sent to MySQL database from $_POST?and one more thing, what is the actual purpose of coding SQL in the same area as coding php when we can use myPHPAdmin to do the sql things?it seems like create a table and add a new row is easier to be done in myPhpAdmin than in the same area as php codes is in,am i right?Please enlighten me more about this subject.thank you

PhpMyAdmin is an administration tool, meaning, you use it for administrative purposes, such as designing and setting up new tables, checking records to diagnose and debug code, modifying table structures when new features in your code are required. It is not a tool which should be used by programs which interact with the database. This is the reason for writing your SQL queries inside your PHP code.

Your PHP script is a little program which will interact with the database. It will tell the database, "I have some data here for you to store," (INSERT), and the database will follow your program's commands. These commands must be written in SQL, a language which the database understands.

Each PHP script serves a very specific purpose in your database application--that is, it performs one task and only that task. As such, it makes sense to write one SQL query that will be stored inside your PHP script and executed whenever the script gets called, since that SQL query describes the function that particular PHP script is supposed to do.

In order to translate the fields in your HTML form into a new row in your table, you must construct a SQL query with the data retrieved from your HTML form ($_POST). This part you have to do by hand. I would recommend looking into Prepared Statements in PHP to learn how to insert the data from the HTML form into the SQL query.

0

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

as what i understand, myPHPadmin is for DDL purpose while query is for DML purpose,is it?and when a user submit a new form, do i need to do the query and do it again for another form?is that how it goes?do the query whenever new row is to be inserted?

is that meant i will need to do query and database connection in the same file as i do $_POST?

Essentially, yes, phpMyAdmin is for all your DDL stuff, while your PHP script performs all your DML stuff, although you can do some DML stuff in phpMyAdmin, but you should really only limit this to debug purposes.

Your PHP script pseudocode should look something like this:

Fetch form field data from $_POST.
Prepare an INSERT SQL query.
Bind the form field values to the parameters in the query.
Execute the query.
Echo the results (if you want some sort of confirmation).

0

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

Yes, if you oversee some minor syntax errors, that is the basics of how you do.

0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.

Yes, but you are using regular statements without sanitizing your inputs, rather than using Prepared Statements like I suggested. Your method above will work, once the syntax errors are corrected, but it will leave you wide open to SQL Injection attacks.

oh yeah.i notice the mistake there.well, when i run the program, only the form which is in enrollment.html file that appear in the browser.when i clicked the submit button,nothing was appear.i've checked the file directory, and everything is seems okay.i created a file named codes in the htdocs document and the directory looks like this C:\xampp\htdocs\Codes.why does the output doesn't come out?

Back up a second. What's the code for your HTML form and your PHP script that you're using for your simplified echo trial? Double check to ensure you have all your form control names correct. What's the output when you just try to echo the form fields back to the browser?

0

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

Back up a second. What's the code for your HTML form and your PHP script that you're using for your simplified echo trial? Double check to ensure you have all your form control names correct. What's the output when you just try to echo the form fields back to the browser?

the output from echo the form is the form that i named it as enrolment. the form is displayed successfully. however, when im trying to submit the data in to the database, nothing comes out. didn't display anything.i've checked everything and it is seems okay.does it got anything to do with something that is out of code?my server or something?Im using xampp anyway.