For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > July 2006 > Email Contact form









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Email Contact form
DoomedLung

2006-07-18, 3:57 am

Hey everyone, I'm new to php scripting so please bear with me.

Basically I have been asked to develop a contact form that stores all
the users input i.e. Name, Message, Email add, etc, etc within the
relevant fields that I have set up in MySQL DB. My problem is that no
user input is being inserted into the fields when I export the DB table
to Excel or PDF, the fields are there but the rest of it is blank!!!???


I have two web pages that 'handle' the email contact form. The 1st page
(contact.php) is the form that posts user input and calls to action the
2nd page (contact_form_handler.php) which inserts the data into the DB
table. Here is the code for both pages.

1st contact.php:

<form method="post" action="contact_form_handler.php">
Email<br><input type="text" name="email"size=30>
Name<br><input type="text" name="name" size=42><br>
Phone:<br><input type="text" name="phone" size=72><br>
Message:<br><textarea name="message" cols=68 rows=12></textarea>
<input type=submit name="submit" value="Enter">
</form>



2nd contact_form_handler.php:

<?
$link = mysql_connect("localhost","theDBName","thePassword");
$dbName = mysql_select_db("theDBName");
$date=date("jS F Y", strtotime($Row[date]));
mail("agreco@playboy.com", "Contact", "New message to the contact
database - $date.");
$email= $_POST["email"];
$name= $_POST["name"];
$phone= $_POST["phone"];
$message=$_POST["message"];
$tableName="Contact";
$query="INSERT INTO $tableName (Email, Name, Phone, Message) VALUES
('$date', '$email', '$name', '$phone', '$message')";
$result=mysql_db_query($dbName, $query, $link);
mysql_close ($link);
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>Thank you!</body>
</html>

I've been searching and searching the web on this topic and have had no
such luck.

Can anyone point me in the right direction please.

Cheers

Sheldon Glickler

2006-07-18, 7:56 am


"DoomedLung" <doomedlung@googlemail.com> wrote in message
news:1153211068.216968.220970@m79g2000cwm.googlegroups.com...
> Hey everyone, I'm new to php scripting so please bear with me.
>
> Basically I have been asked to develop a contact form that stores all
> the users input i.e. Name, Message, Email add, etc, etc within the
> relevant fields that I have set up in MySQL DB. My problem is that no
> user input is being inserted into the fields when I export the DB table
> to Excel or PDF, the fields are there but the rest of it is blank!!!???
>
>
> I have two web pages that 'handle' the email contact form. The 1st page
> (contact.php) is the form that posts user input and calls to action the
> 2nd page (contact_form_handler.php) which inserts the data into the DB
> table. Here is the code for both pages.
>
> 1st contact.php:
>
> <form method="post" action="contact_form_handler.php">
> Email<br><input type="text" name="email"size=30>
> Name<br><input type="text" name="name" size=42><br>
> Phone:<br><input type="text" name="phone" size=72><br>
> Message:<br><textarea name="message" cols=68 rows=12></textarea>
> <input type=submit name="submit" value="Enter">
> </form>
>
>
>
> 2nd contact_form_handler.php:
>
> <?
> $link = mysql_connect("localhost","theDBName","thePassword");
> $dbName = mysql_select_db("theDBName");
> $date=date("jS F Y", strtotime($Row[date]));
> mail("agreco@playboy.com", "Contact", "New message to the contact
> database - $date.");
> $email= $_POST["email"];
> $name= $_POST["name"];
> $phone= $_POST["phone"];
> $message=$_POST["message"];
> $tableName="Contact";
> $query="INSERT INTO $tableName (Email, Name, Phone, Message) VALUES
> ('$date', '$email', '$name', '$phone', '$message')";
> $result=mysql_db_query($dbName, $query, $link);
> mysql_close ($link);
> ?>
> <html>
> <head>
> <title>Untitled Document</title>
> </head>
> <body>Thank you!</body>
> </html>
>
> I've been searching and searching the web on this topic and have had no
> such luck.
>
> Can anyone point me in the right direction please.
>
> Cheers
>


What I would do is:
Combine the pages with the submit logic on top.
Make the action of the page "".
Enclose the logic for submission within a if (isset($_POST['submit']))
{ the logic }.
Put in a header to go where you want on success. header("Location:
where-you-want-to-go");

You can then put in error checking to see if all the required fields are
there or to prevent a double submission of the primary field, etc. and send
a message to the user if not enough.

Shelly


ClickToWalk

2006-07-18, 7:56 am

Sheldon Glickler wrote:
> "DoomedLung" <doomedlung@googlemail.com> wrote in message
> news:1153211068.216968.220970@m79g2000cwm.googlegroups.com...

Maybe just a typo, but you have theDBName where username should be.
[color=darkred]

Here you are inserting 5 values into only 4 table fields, i.e. Date has
been excluded from the list of fields to insert data.

as it is

$date -> Email
$email -> Name
$name -> Phone
$phone -> Message
$message -> where?
[color=darkred]
>
> What I would do is:
> Combine the pages with the submit logic on top.
> Make the action of the page "".
> Enclose the logic for submission within a if (isset($_POST['submit']))
> { the logic }.
> Put in a header to go where you want on success. header("Location:
> where-you-want-to-go");
>
> You can then put in error checking to see if all the required fields are
> there or to prevent a double submission of the primary field, etc. and send
> a message to the user if not enough.
>
> Shelly
>
>


As Shelly suggests you should add some error checking, i.e. echo
variables to check that they contain what you expect/hope them to.

If you are running a local server you can alter the configuration to
display different degrees of error which may help.

Read http://uk2.php.net/manual/en/ref.errorfunc.php

Regards
Matt




--
"I'm an idealist. I don't know where I'm going, but I'm on my way." -
Carl Sandburg

http://clicktowalk.com

Page design © Matthew McCabe <http://mattmadethis.com> -
http://mattmadethis.com

Site hosted by Xeriom Networks <http://xeriom.net/in/1019> -
http://xeriom.net/in/1019
Sheldon Glickler

2006-07-18, 6:57 pm

BTW, I tried a simplified form of his original problem where I put a text
field in page1.php and filled it and had the action statement of the form
going to page2.php where I echoed the text field. It worked perfectly (with
method POST). ClickToWalk, I think you found his problem as being the
insert.

Shelly

"ClickToWalk" <m_t_hill@hotmail.com> wrote in message
news:44bce887$1_1@mk-nntp-2.news.uk.tiscali.com...
> Sheldon Glickler wrote:
>
> Maybe just a typo, but you have theDBName where username should be.
>
>
> Here you are inserting 5 values into only 4 table fields, i.e. Date has
> been excluded from the list of fields to insert data.
>
> as it is
>
> $date -> Email
> $email -> Name
> $name -> Phone
> $phone -> Message
> $message -> where?
>
>
> As Shelly suggests you should add some error checking, i.e. echo variables
> to check that they contain what you expect/hope them to.
>
> If you are running a local server you can alter the configuration to
> display different degrees of error which may help.
>
> Read http://uk2.php.net/manual/en/ref.errorfunc.php
>
> Regards
> Matt
>
>
>
>
> --
> "I'm an idealist. I don't know where I'm going, but I'm on my way." -
> Carl Sandburg
>
> http://clicktowalk.com
>
> Page design © Matthew McCabe <http://mattmadethis.com> -
> http://mattmadethis.com
>
> Site hosted by Xeriom Networks <http://xeriom.net/in/1019> -
> http://xeriom.net/in/1019



DoomedLung

2006-07-20, 7:57 am

Hey, thanks for your speedy responses. Much appreciated!

Your right it was the INSERT that wasn't population the fields in the
MySQL table.

All sorted now.

Cheers

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com