PHP Classes

File: Example_simple.php

Recommend this page to a friend!
  Classes of Edoardo   PHP Form To DB   Example_simple.php   Download  
File: Example_simple.php
Role: Example script
Content type: text/plain
Description: Example1
Class: PHP Form To DB
Validate form submission and save to MySQL records
Author: By
Last change:
Date: 11 years ago
Size: 589 bytes
 

Contents

Class file image Download
<?php

//PostToDb.class.php

/* Example: without validating */


include_once('FormToDb.class.php');

//Incoming five vars: $_POST['name'], $_POST['email'], $_POST['message'], $_POST['checkbox_name'], $_POST['submit_req']

if( isset($_POST['submit_req']) )
{
   
$object = new FormToDb(_DB_HOST_, _DB_USER_, _DB_PASSWORD_, _DB_NAME_, 'my_table_name');
       
   
//...ignore these post variables
   
$object->toIgnore = array('submit_req', 'checkbox_name');

   
//...then cycle and save
   
$object->getFromPost($_POST);
    if(
$object->getErrors() == FALSE);
       
$object->save();
}


?>