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: 3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org (view raw or flat)
Thread:
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 :

http://www.siddha.ca/healthnotes/add.php

view the addressbook table at:

http://www.siddha.ca/healthnotes/index.php

Michael

-----

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

<body>

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

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

		<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">
         Name:<br>
         <input name="name" type="text" size="50">
         <p>
         Address:<br>
         <textarea name="address" rows="6" cols="40"></textarea>
         <p>
         Tel:<br>
         <input name="tel" type="text" size="10">
         <p>
         Email:<br>
         <input name="email" type="text" size="30">
         <p>
         <input type="submit" name="submit" value="Add">
         </form>
<?
}
else
{
         // 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
password=$pass");

         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
         pg_close($connection);
}
?>
</body>
</html> 

Responses

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-2014 The PostgreSQL Global Development Group