PHP Classes
elePHPant
Icontem

File: Requests/example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Arkadiusz Malinski  >  Requests  >  Requests/example.php  >  Download  
File: Requests/example.php
Role: Example script
Content type: text/plain
Description: Exmple of using this class
Class: Requests
Validate HTTP request variable values
Author: By
Last change:
Date: 8 years ago
Size: 1,705 bytes
 

Contents

Class file image Download
<html>
<head>
<title>example page</title>
</head>
<body>
<?
 
include 'class.requests.php';
  include
'adodb.inc.php';

  try {
   
$requests = new Requests();
    if(
$requests->dataExist(METHOD_POST)) {
     
// modyfying conditions values
     
$requests->defineCondition(MIN_LENGHT, 3);
     
$requests->defineCondition(MAX_LENGHT, 25);

     
// adding conditions to fieldname
     
$requests->addCondition(METHOD_POST, "id", VALID_NUMBERS);
     
$requests->addCondition(METHOD_POST, "name", MIN_LENGHT);
     
$requests->addCondition(METHOD_POST, "name", MAX_LENGHT);
     
$requests->addCondition(METHOD_POST, "email", VALID_EMAIL);

     
// test all definied conditions; on failure throws an exception;
     
$requests->testAllConditions();
     
     
// it's seems to be ok an we can insert data into database
     
$sql = "insert into testTable(name,email) VALUES('".
            
$requests->getPost("name")."', '".$requests->getPost("email").
            
"') WHERE id = ".$request->getPost("id");

     
$DB = NewADOConnection('mysql');
     
$DB->Connect($server, $user, $pwd, $db);
     
     
$result = $DB->Execute($sql);
    } else {
       
?>
<form action="example.php" method="POST">
            <input type="hidden" name="id" value="233">
            <input type="text" name="name" value=""><br>
            <input type="text" name="email" value=""><br>
            <input type="submit" value="Send">
            </form>
        <?
   
}
  } catch (
RequestsException $re) {
       echo
"Error in sending data. Please return to form an fill it with corrent values";
  } catch (
Exception $error) {
          echo
"Error: ".$error->getMessage();
  }
?>
</body>
</html>