PHP form Creates Blank DB entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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> 


[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux