Documentatoin -- class: mysqlForm
- Class : mysqlForm
- This class can print a mysql result resource and Create HTML form for MySql table.
- Initialization : $obj=new mysqlForm($linkresource,$databasename)
- Argument 1 : The link.such as :
$link=mysql_connect('localhost', 'user', 'password');
- Argument 2 : The table name. Suppose we, will work with 'employee' table.
- Example: Now this class can be initialized as : $obj=new mysqlForm($link,'employee');
- Form fields and there labels are organized in table.
- Method : printResult($result,$format="border=1")
- This method prints a result source as table.
- Argument 1 : the result resource. such as : $result
- Argument 2 : (Optional) format of table.
- Example: $obj->printResult($result,"border=1,cellpadding=2")
- Column name used as table header.(see test.php for details)
- Method : printForm($table,$action,$skip="-1")
- This method creats an HTML form for an stracture of MySql table
- Argument 1 : Table name, for which the from will be created.
- Argument 2 : Action attrebute of form.
- Argument 3 : (Optional)Index of columns to skip. For whom form field is not required.
- This skip index list should be Comma separated string format. Such as : "0,4,6"
it skips 0,4 and 6 indexd columns of table and dont create form field for them.
- The value of 'method' attrebute of form is POST.
- Name of field :All fields of form will be named and labeled as relevent column name of MySql table
- Length : Length of a field is :(length of column datatype+5).
Such as, for varchar(30) column, field size will be 35.
- Default field type is text.
- If length is more then 50, the field will be text area.
- If the column name of table is password, the field will be password.
- For ENUM columns, <select> field will be created containing its values.
- When submitted, form will submit to 2nd argumented value.
- Example : $obj->printForm("user","insert.php",'0,3');
It creates a form for all fields of 'user' table without 0 and 3 indexed column.
When submitted, it will submit to 'insert.php' file.
- To test the example : 'test.php'
- Execute the queryes in mysqlForm.sql file
- Look at the values in conn.php file
- Run the example file 'test.php'. It explains how to use this class.
- Insert a new user data (if you are testing with your won database and table, you have to edit 'conn.php' and 'insert.php').