christianix.de

-> Main -> PHP-Tutorial -> competition/manage/index.php

<?php
define
"TMPL_PATH""../../templates" );
define"TMPL_FILE""adminform.tmpl" );
define"HOST""localhost" );
define"USER""<USERNAME>" );
define"PASSWD""<PASSWORD>" );
define"DB""<DATABASENAME>" );

/* Home:   http://pear.php.net/package/HTML_Template_IT */
require_once "HTML/Template/IT.php";

// Init
$template = new HTML_Template_ITTMPL_PATH );
$template->loadTemplatefileTMPL_FILEtruetrue );
$name "";
$email "";
$bear "";
$status "";

if (
$_SERVER["REQUEST_METHOD"] == "POST") { // process input
    
if ( !($_POST["name"] && $_POST["email"] && $_POST["bear"]) ) { // error
        
if ( $_POST["name"] ) $name .= $_POST["name"];
        else 
$status .= "Name is missing.<br>";
        if ( 
$_POST["email"] ) $email .= $_POST["email"];
        else 
$status .= "E-Mail is missing.<br>";
        if ( 
$_POST["bear"] ) $bear .= $_POST["bear"];
        else 
$status .= "Suggestion is missing.<br>";
        
$status .= "Please fill in the required information!";
    } else { 
// no error
        
$con dbx_connectDBX_MYSQLHOSTDBUSERPASSWD ) or
               die( 
"<html><body>Error connecting to database!</body></html>" );
        
$name .= dbx_escape_string$con$_POST["name"] );
        
$email .= dbx_escape_string$con$_POST["email"] );
        
$bear .= dbx_escape_string$con$_POST["bear"] );
        
$result dbx_query$con"INSERT INTO competition (name, email, bear) VALUES ('".$name."','".$email."','".$bear."')" );

        if ( 
$result ) {
            
$name "";
            
$email "";
            
$bear "";
            
$status .= "Data was successfully written to database!";
        } else {
            
$status .= "Error while inserting data!";
            
// status .= dbx_error( $con );
        
}
        
dbx_close$con );
    }
// else show empty formular

// Data processing
$template->setVariable"name"$name );
$template->setVariable"email"$email );
$template->setVariable"bear"$bear );
$template->setVariable"status"$status );
$template->parseCurrentBlock();

// Create HTML output
header ( 'Content-Type: text/html; charset=utf-8' );
$template->show();
?>
Verantwortlich/Responsible: Martin Christian (martin at christianix dot de)