pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Hanna <zen@hwcn.org>
To: pgsql-php@postgresql.org
Subject: PHP form Creates Blank DB entries
Date: Mon, 30 Jun 2003 12:16:46 -0400
Message-ID: <3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org> (raw)

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>


view thread (6+ messages)  latest in thread

Message-ID: <3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org>
Permalink:  ../3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org/
Also on:    postgresql.org/message-id/3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: zen@hwcn.org
  Subject: Re: PHP form Creates Blank DB entries
  In-Reply-To: <3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org>
  References: <3EC8256A-AB16-11D7-8634-00039308EB2C@hwcn.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox