Re:PostgreSQL and PHP - Mailing list pgsql-general

From sheila bel
Subject Re:PostgreSQL and PHP
Date
Msg-id 20000211205046.16845.qmail@hotmail.com
Whole thread Raw
List pgsql-general
Hi, I'm trying an example from a book using PHP and PostgreSQL.
This application lets you create a form on a web page and
have the output emailed directly to you. It also stores the
data input into a database table. If you are not interested in
PHP please ignore this message.

This is the actual code :

<?PHP
//step #2 handle the output from the form

if ( strlen($name)>0 ):
   if (strlen($email)<1):
    echo "<center><b>Please enter an E-Mail address</b>
    <br>Use your browser's BACK key to return</center>";
    exit;
  endif;

  $name = addslashes($name);
  $email = addslashes($email);
  $phone = addslashes($phone);
  $message = addslashes($message);

$subject_field = "My Form";
$SENDTO = "sheilabel@hotmail.com";

$BODY = "FROM: $name
\nPhone : $phone
\nE-Mail: $email
\nMessage: $comments";

mail ($SENDTO, $subject_field, $BODY, "From:$email");

//save the results in our table
//open the database

$conn=pg_Connect("","","","","mydatabase");
if (!$conn) {echo "An error occured in connection.\n";exit;}

//insert a new record to store the data

$result = pg_Exec($conn, "insert into myform (name,phone,email,message)
VALUES ('$name', '$phone', '$email', '$message' ");
if (!$result)  {echo "An error occured in connection.\n";exit;}

//return to the form
$CP="contactus.html";
Header("REFRESH: 2 ; URL=$CP");

echo "<html><bodybgcolor=WHITE><center>
            <p> <p> <p> ";
echo "<font face= \" helvetica, arial \" color=\"#000080\">";
echo "Your message has been<b> successfully</b> sent to <b> $SENDTO</b>";
echo "<br>Moving now to the <b>$CP</b> section ....";
echo "</center></body></html>";
exit;
endif;
?>

<html>
<head>
  <title>---contactus.html </title>
</head>
<body>

//step #1
//create the form

<form method='PUT' action='contactus.html'>
<table> <tr><td>
   Type in your Name:
   <INPUT TYPE="text" NAME="name" VALUE="" SIZE=20 MAXLENGTH=40 >
   <br>
   Type in your E-Mail:
   <INPUT TYPE="text" NAME="email" VALUE="" SIZE=20 MAXLENGTH=40>
   <br>
   Type in your Phone:
   <INPUT TYPE="text" NAME="phone" VALUE="" SIZE=8 MAXLENGTH=20>
   <br>
   Type in your Message:
   <TEXTAREA NAME="message" ROWS=3 COLS=40 WRAP=VIRTUAL></TEXTAREA>
   <p>
   <INPUT type=SUBMIT name=SUBMIT value="Press to Submit">
</td></tr>
</table>
</body>
</head>

I've also created this little database:
createdb mydatabse;
create table myform(name text,email text, phone text, message text);

>>Now what is confusing me is why in the html code they have
used // for commenting since it shows in the web page.

I've saved this file under the name example.php3 when I view this
in the web browser as :

http://www.myserver.com/mydirectory/example.php3

I see a form and I fill it out. It is supposed to check for the email box
and if empty return an error message, it doesn't do that.
The file is not submitted and nothing is emailed to me. When I click
on Submit it just empties the form and does not give me any messages
like its supposed to.

>>If you have any idea what seems to be the problem please let me know
since I've been struggling with this for a day now.

Thank you for your time,
-Sheila

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


pgsql-general by date:

Previous
From: Lamar Owen
Date:
Subject: Re: [GENERAL] Alpha FreeBSD
Next
From: Jeff Davis
Date:
Subject: Re: [GENERAL] Re:PostgreSQL and PHP