WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors
Categories : PHP, Variables, Errors and Logging Click here to Update Your Picture
Brian Tafoya
Date : Apr 16th 2004
Grade : 5 of 5 (graded 1 times)
Viewed : 19901
File : 3823.php
Images : No Images for this code example.
Search : More code by Brian Tafoya
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

PURPOSE:
Simply to keep PHP from geeking out when an undefined POST, GET, or SESSION variable
is meet, always returning a defined variable. (In particular for use in form check boxes.)
----
USAGE:
getvar( mixed var [, int ])
postvar( mixed var [, int ])
sessionvar( mixed var [, int ])

include_once("get_post.php");

Expecting $_GET["somevar"], use instead getvar("somevar")
Expecting $_POST["somevar"], use instead postvar("somevar")
Expecting $_SESSION["somevar"], use instead sessionvar("somevar")

Example:

$sql = "INSERT INTO tbl_something
                SET some_column = " . postvar("checkbox_name",true) . ",
                        some_other_column = '" . postvar("text_box_name") . "'";
                        
The first argment is the variable name, the second tells the function to return an int (0)
on false.


<?php
/*
----
getvar/postvar - When you just don't know what to expect!
----
Brian Tafoya
briantafoya.com
"Taking over the planet one open source script at a time!"
----
PURPOSE:
Simply to keep PHP from geeking out when an undefined POST, GET, or SESSION variable
is meet, always returning a defined variable. (In particular for use in form check boxes.)
----
USAGE:
getvar( mixed var [, int ])
postvar( mixed var [, int ])
sessionvar( mixed var [, int ])

include_once("get_post.php");

Expecting $_GET["somevar"], use instead getvar("somevar")
Expecting $_POST["somevar"], use instead postvar("somevar")
Expecting $_SESSION["somevar"], use instead sessionvar("somevar")

Example:

$sql = "INSERT INTO tbl_something
        SET some_column = " . postvar("checkbox_name",1) . ",
            some_other_column = '" . postvar("text_box_name") . "'";
           
The first argment is the variable name, the second tells the function to return an int (0)
on false.
           
*/

/*
Prevent undefined get variables
*/
function getvar($name,$isint="") {
    if(isset(
$_GET[$name])) {
        return
$_GET[$name];
    } else {
        if(
$isint) {
            return
0;
        } else {
            return
"";
        }
    }
}

/*
Prevent undefined post variables
*/
function postvar($name,$isint="") {
    if(isset(
$_POST[$name])) {
        return
$_POST[$name];
    } else {
        if(
$isint) {
            return
0;
        } else {
            return
"";
        }
    }
}

/*
Prevent undefined session variables
*/
function sessionvar($name,$isint="") {
    if(isset(
$_SESSION[$name])) {
        return
$_SESSION[$name];
    } else {
        if(
$isint) {
            return
0;
        } else {
            return
"";
        }
    }
}
?>



DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
Intelligent 404 Handler
Categories : PHP, Errors and Logging
PHP Event Logger
Categories : PHP, Log Files, Errors and Logging, Beginner Guides
How to know which input button of type image was pressed in a form with multiple image buttons (_x and _y) in PHP?
Categories : PHP, Variables, HTML
Visits-tracking
Categories : PHP, Databases, MySQL, Errors and Logging, Functions
How to control the number of decimal places when outputting numbers.
Categories : PHP, Strings, Variables
translate.php - Assocciative array example, passing a reference to a function.
Categories : PHP, Arrays, Languages, Variables
Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem
Global Dump Highlighted
Categories : PHP, Variables, Global Variables
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
serialize -- Generates a storable representation of a value
Categories : PHP, PHP Functions, Variables
Example of function to send out email if error occurs
Categories : PHP, Email, Debugging, Errors and Logging
Building a basic error handler with custom error types
Categories : PHP, PHP Classes, Errors and Logging
This functions compares the current PHP version with a desired version. Because of the 3 tiered version system, a direct compare of a string to phpversion() will not be accurate.
Categories : PHP Configuration, PHP, Variables
Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI
Categories : Variables, PHP Options and Info, Arrays, URLs, PHP