80 likes | 201 Views
Database to HTML and Back again A programmers tale. DB to HTML. To get information from a Database table into a HTML file we need to use SQL and PHP 1. get the data from the table 2. put the data into PHP variables 3. put the variables into the values attributes or HTML
E N D
DB to HTML • To get information from a Database table into a HTML file we need to use SQL and PHP 1. get the data from the table 2. put the data into PHP variables 3. put the variables into the values attributes or HTML The document is then printed
DB to HTML • 1. get the data from the table • USE SQL SELECT statement • The SQL fields and table names must match the table
DB to HTML • 2. put the data into PHP variables The names of the PHP variables reflect easily recognizable names based on the table and fields. The data from the field names goes into the variable names.
DB to HTML 3. put the variables into the values attributes or HTML If you are using a form the variables should go into value attributes in many cases.
HTML to DB • To get HTML form information into a Database we just reverse the process. 1. Take the HTML form elements and place them into PHP variables 2. Take the variables and put them into a SQL statement.
HTML to DB • 1. Take the HTML form elements and place them into PHP variables This is first accomplished by naming the name attribute values with recognizable names.
HTML to DB • 2. Take the variables and put them into a SQL statement. • The names of the variables will be the values of the SQL statement. • The names to the left of the = signs are the names of the fields