Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Email Contact form
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


Report this thread to moderator Post Follow-up to this message
Old Post
DoomedLung
07-18-06 08:57 AM


Re: Email Contact form
"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



Report this thread to moderator Post Follow-up to this message
Old Post
Sheldon Glickler
07-18-06 12:56 PM


Re: Email Contact form
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.
 

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?
 
>
> 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 sen
d
> 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

Report this thread to moderator Post Follow-up to this message
Old Post
ClickToWalk
07-18-06 12:56 PM


Re: Email Contact form
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



Report this thread to moderator Post Follow-up to this message
Old Post
Sheldon Glickler
07-18-06 11:57 PM


Re: Email Contact form
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


Report this thread to moderator Post Follow-up to this message
Old Post
DoomedLung
07-20-06 12:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:05 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.