This php code generates html forms based on your mysql query, the advantage of this is that you can unify the names of your tables, $_POST variable, form name variables, and it's reusable to other form outputs you like.
<?php
//this function process the mysql query
function form_get ( $form_query = NULL , $form_name = NULL , $form_action = NULL , $form_method = 'post' , $form_cancel = 0 ) {
//object oriented query
$row = $this -> dbc -> query ( $form_query );
$output = NULL ;
$output .= '<form action="' . $form_action . '" method="' . $form_method . '">' ;
//generate form items based on fields
while ( $field = $row -> fetch_field ()) {
//print show_array($field);
//form field error class
isset( $_SESSION [ str_replace ( ' ' , '_' , $field -> name )]) ? $input_class = $_SESSION [ str_replace ( ' ' , '_' , $field -> name )]: $input_class = '' ;
//form field default value
isset( $_POST [ str_replace ( ' ' , '_' , $field -> name )]) ? $field_value = $_POST [ str_replace ( ' ' , '_' , $field -> name )]: $field_value = '' ;
//form field password type
( preg_match ( '/\s*password\s*/' , $field -> name )) ? $field_type = 'password' : $field_type = 'text' ;
//form input/textarea type
( $field -> length > 100 ) ? $input_type = '<label>' . ucwords ( $field -> name ) . '</label><text area class="' . $input_class . '" name="' . str_replace ( ' ' , '_' , $field -> name ) . '" cols="20" rows="5">' . $field_value . '</text area>' :
$input_type = '<label>' . ucwords ( $field -> name ) . '</label><input class="' . $input_class . '" type="' . $field_type . '" name="' . str_replace ( ' ' , '_' , $field -> name ) . '" value="' . $field_value . '"/>' ;
$output .= $input_type ;
//reset empty error class
$_SESSION [ str_replace ( ' ' , '_' , $field -> name )] = '' ;
}
//cancel submit button switch
( $form_cancel ) ? $cancel = '<input name="cancel" type="submit" value="Cancel">' : $cancel = '' ;
//form sumit button
$output .= '<input type="submit" name="' . $form_name . '" value="' . ucwords ( $form_name ) . '" /> ' . $cancel ;
$output .= '</form>' ;
return $output ;
}
//with a few lines of codes you can automatically generate the registration form, of course you need to setup a database for this to work
function user_register () {
//form get function input
$form_query = 'SELECT name as user, password, password as "retype password", email FROM user LIMIT 1' ;
$form_name = 'register' ;
$form_action = '' ;
$form_method = 'post' ;
$form_cancel = 1 ;
$output = NULL ;
if(isset( $_GET [ 'q' ]) && $_GET [ 'q' ] == 'register' ) {
$output .= $this -> form_get ( $form_query , $form_name , $form_action , $form_method , $form_cancel );
} else {
$output .= '<span class="register">Not a member yet? <a href="' . BASE_URL . 'registration">' . ucwords ( $form_name ) . '</a></span>' ;
}
return $output ;
}
?>
Simple db results paging example Categories : PHP , MySQL , Databases , Form Processing A login page that require username, password and userlevel. Categories : PHP , Security , Sessions , MySQL , Databases bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL , PHP , MySQL , Complete Programs , Databases This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases , MySQL , Complete Programs , PHP , Databases Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0 Categories : PHP , Sessions , Databases , MySQL for each record, do this to the first record, and do that to any subsequent record Categories : PHP , Databases , MySQL , Beginner Guides DBXML- A Class to backup databases in XML Format using web interface Categories : PHP , PHP Classes , Databases , MySQL , XML Dynamically generated pop-ups (Select items) Categories : PHP , HTML and PHP , MySQL , Databases A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT Categories : PHP , MySQL , Java Script , Databases Convert a File database into MySQL Categories : PHP , Filesystem , Databases , MySQL , Beginner Guides DB Connection Function with error handling and email failure notices Categories : PHP , MySQL , Errors and Logging , Databases , Errors and Logging database,php,mysql,demo,example,php3,training,tutorial,codes,code Categories : Databases , MySQL , PHP , PHP Options and Info Displaying records of database in more than one page (paging) Categories : Databases , MySQL , PHP MySQL Class to ease Database connectivity Categories : MySQL , PHP Classes , Databases , PHP This is a very simple BBS that uses MySQL Categories : MySQL , Databases , Complete Programs , PHP