Conversion tables A-K
  Conversion tables L-Z
  SPAM database query
  Reverse WHOIS utility
  North America area codes
  PHP Example forums

PHP example repository.

Back to examples
Simple method of inserting a record into Postgresql from a web based form

Allows you to build a quick and simple form and then automatically format a SQL query to insert the data into a specified table. All fields within the form need to be named with the prefix INPUT_ . The rest of the field names relate to the name of the table field in the database.


$table_name "example";

$query "insert into $table_name ";
$vars  NULL;
$vals  NULL;
        while (list (
$key$val) = each ($HTTP_POST_VARS)) 
$vals $vals.(!empty($vars)?", ":"")."'".addslashes($val)."'";
$vars $vars.(!empty($vars)?", ":"").substr($key,6);
$query.= " ($vars) values ($vals)";

// Use the variable $query within pg_exec

<form name="form1" method="post" action="">
Name <input name="input_name" type="text" maxlength="15">
Address 1 <input name="input_add1" type="text">
Address 2 <input name="input_add2" type="text">
Town / City <input name="input_town" type="text">
State <input name="input_state" type="text">
ZIP <input name="input_zip">
<input name="input_more" type="checkbox" value="1"> Wants futher communication
<input name="add" type="submit" class="PHPBODY" value="Add">
<?php print($query);?>