WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple PHP Form Auto Generation based on MySQL query
Categories : PHP, Form Processing, Databases, MySQL, Sessions Click here to Update Your Picture
Daniel Honrade
Date : Oct 28th 2009
Grade : 4 of 5 (graded 3 times)
Viewed : 4562
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Daniel Honrade
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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;
}
?>



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
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Simple db results paging example
Categories : PHP, MySQL, Databases, Form Processing
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
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
This class splits the results of the query into multiple pages like what the search engine does.
Categories : PHP Classes, PHP, MySQL, Databases
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Load delimited textfile into MySql table.
Categories : PHP, Databases, MySQL
This script is a contact form between users of a website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps
html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
PHP Calendar Web App
Categories : PHP, Databases, MySQL, Date Time, Calendar
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
AITSH Statistics
Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL