Skip site navigation (1) Skip section navigation (2)

PHP form Creates Blank DB entries

From: Michael Hanna <zen(at)hwcn(dot)org>
To: pgsql-php(at)postgresql(dot)org
Subject: PHP form Creates Blank DB entries
Date: 2003-06-30 16:16:46
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php
I can post with this code, however the result is a new row in the 
table, where each column is blank except for the serial number. Any 
ideas? PG 7.3.3, PHP 4.3.0

it can be tested at :

view the addressbook table at:



<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<head><basefont face="Arial"></head>
<h2>Address Book</h2>

// form not yet submitted
// display form
if ($_POST['submit'] != "Add")

		<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">
         <input name="name" type="text" size="50">
         <textarea name="address" rows="6" cols="40"></textarea>
         <input name="tel" type="text" size="10">
         <input name="email" type="text" size="30">
         <input type="submit" name="submit" value="Add">
         // form submitted
         // prepare to insert data

         // database access parameters
         // alter this as per your configuration
         $host = "localhost";
         $user = "<MYUSER>";
         $pass = "<MYPASS>";
         $db = "test";

         // open a connection to the database server
         $connection = pg_connect("host=$host dbname=$db user=$user

         if (!$connection)
                 die("Could not open connection to database server");

         // error checks on form submission go here

         // generate and execute a query
         $query = "INSERT INTO addressbook VALUES
(nextval('addressbook_id_seq'), '$name', '$address', '$tel', '$email')";
         $result = pg_query($connection, $query) or die("Error in query:
$query. " . pg_last_error($connection));

         echo "Data successfully added.";

         // close database connection


pgsql-php by date

Next:From: Frank BaxDate: 2003-06-30 17:23:17
Subject: Re: PHP form Creates Blank DB entries
Previous:From: scott.marloweDate: 2003-06-30 12:25:51
Subject: Re: Simulating a POST request

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group