Hello. I am using php/Postgre and the connection between those two is working fine. However, I can't get values from an HTML form to pass into the php script where I have an INSERT statement. Anyone have any ideas what's going on? Here is the code...
HTML:
<HTML>
<BODY>
<FORM ACTION="add-entry.php" METHOD="GET">
<TABLE BORDER=1>
<TR>
<TD>
<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>Name</TD>
<TD><INPUT TYPE="TEXT" NAME="name" VALUE=""></TD>
</TR>
<TR>
<TD>Phone</TD>
<TD><INPUT TYPE="TEXT" NAME="phone" VALUE=""></TD>
</TR>
<TR>
<TD>E-mail</TD>
<TD><INPUT TYPE="TEXT" NAME="email" VALUE=""></TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=CENTER>
<INPUT TYPE="SUBMIT" VALUE="Add Entry">
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
PHP:
<HTML>
<BODY>
<?PHP
// Connect to PostgreSQL.
$db = pg_connect("my connect values");
if( !$db )
{
echo "Could not connect!";
exit;
}
// Create an SQL statement to insert the information into the table.
//
$query = "INSERT INTO addresses (name, phone, email) VALUES ( '$name', '$phone', '$email' )";
// Connect to the AddressBook database; run the SQL statement.
//
$result = pg_Exec( $db, $query );
if( !$result )
{
echo "No result set returned!";
exit;
}
// Get the results of the SQL statement.
//
$rows = pg_NumRows( $result );
if( $rows = 0 )
{
echo "Add Failed.";
exit;
}
// Get the record (i.e., row) that was just added.
//
$query = "SELECT * FROM Addresses WHERE \"name\" = '$name';";
$result = pg_Exec( $db, $query );
$row = pg_Fetch_Row( $result, 0 );
$nameResult = $row[0];
$phoneResult = $row[1];
$emailResult = $row[2];
echo "Name = $nameResult<BR>";
echo "Phone = $phoneResult<BR>";
echo "E-mail = $emailResult<BR>";
pg_Close( $db );
?>
<H3>Add Okay!</H3>
</BODY>
</HTML>
When I add static values into the INSERT statement it works fine however, with the following code it enters a blank row into Postgre. So I think there is a problem between the form and php. Please help!
😕
Andy