Zend - The PHP Company




Databases

Add Code


Dynamic Website  

Type: application
Added by: hanigamal
Entered: 14/02/2005
Last modified: 02/12/2004
Rating: - (fewer than 3 votes)
Views: 7277
Snippet which retrieves a field from the DB and show it in the body between included header page and footer page


<?php
// if file is not exist then goto first page
   
if (!isset($_GET['p'])) {
             include(
"error.php");
        }
        else {
             
$pp "" $_GET['p'] . "" ;
        }

###########################################################################
// Verifying PHP config & allow the script to work with register_globals OFF
if ( function_exists('ini_get') ) {
    
$onoff ini_get('register_globals');
} else {
    
$onoff get_cfg_var('register_globals');
}
if (
$onoff != 1) {
    @
extract($HTTP_SERVER_VARSEXTR_SKIP);
    @
extract($HTTP_COOKIE_VARSEXTR_SKIP);
    @
extract($HTTP_POST_FILESEXTR_SKIP);
    @
extract($HTTP_POST_VARSEXTR_SKIP);
    @
extract($HTTP_GET_VARSEXTR_SKIP);
    @
extract($HTTP_ENV_VARSEXTR_SKIP);
}

// database info.
require ("includes/cfg.security.inc");

// Connecting Database
$link mysql_connect($db_server,$db_username,$db_pass)or
die (
"<p align=center>Error while connecting Database</p>");

// Selecting Database
mysql_select_db ($db_name,$link)or
die (
"<p align=center>Database isn't exist on server</p>");

// Fetching results
$results mysql_query ("SELECT * FROM `$table` WHERE name='$p'");
$data mysql_fetch_row($results);

// Here we can make it more specific
echo $data[2];
mysql_close($link);

?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories