PHP Classes

File: Requests/example.php

Recommend this page to a friend!
  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: 16 years ago
Size: 1,705 bytes


Class file image Download
<title>example page</title>
include 'class.requests.php';

  try {
$requests = new Requests();
$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;
// 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">
  } catch (
RequestsException $re) {
"Error in sending data. Please return to form an fill it with corrent values";
  } catch (
Exception $error) {
"Error: ".$error->getMessage();