This Message Forum is no longer in use

Please use the new Bravenet Help Forums FOUND HERE

General Forum
This Forum is Locked
Author
Comment
Help with PHP script???

Hi, I was wondering if anyone had any idea how to help me with a small problem. I am trying to make an email form for a puppy questionnaire on my website. I am not very savy when it comes to websites but I found a tutorial and made a basic php script for my form I built. I use Dreamweaver for all of this btw.

When I fill out the form on my site

http://www.exysdobermans.com/pupquest.html

all I get back in my email are my identifying fields, none of the user inputted information is there. It doesn't give me anything, no name, email, comments, nothing.

The script I have checked 100 times, is there something else I need to do? I placed the html file and the php file in my main directory since I was told that it would work from anywhere, should I not have done that? Is there a step I am missing for this to work?

Please help if you can, I spent 2 days working on this stupid form, it is depressing for it to have failed. Please remember I'm so basic it isn't funny, so any help needs to be explained as though I'm a moron! lol

Browser: Firefox 3.5

OS: XP

Re: Help with PHP script???

The page is saved as a static html. Try saving it as a php page, ie. pupquest.php. If you are using Dreamweaver I would suggest you create a new php page, then copy everything below the "php" tag from the page your form is on into the new page, save it as pupquest.php and see if it doesn't work then. Also make sure you have it binding to your MySQL database.

Browser: Firefox

OS: XP

Re: Help with PHP script???

Isn't PHP a script to tell the html page what to do? Or am I totally off base. If I change it from html to php will it still show up and look the same?

Binding to a what database? I'm completely lost there. I dont even know what that is.

Browser: Firefox 3.5

OS: XP

Re: Help with PHP script???

A basic html file is static. You have your form set up nicely, but if you want to collect the data people submit you either have to bind it to a mysql database with tables for the fields, or you could set them up using spry. A page built in php will display like any other. The difference is that you can integrate it with a server side data source. You have built a static page, where what you are looking for is a dynamic page. Php is how you do that.

Browser: Firefox

OS: XP

Re: Help with PHP script???

Ok, I understood a bit of that. Are there instructions for how to do that on Bravenet?

Thank you for your help. I feel like such an idiot....sigh.

Browser: Firefox 3.5

OS: XP

Re: Help with PHP script???

I don't think bravenet can help you with that. They provide a service, but not a lot of instruction.

You said you were using Dreamweaver. Dreamweaver is very user friendly when it comes to setting up dynamic sites. You will have to build a MySQL database first and make tables for the information you are collecting. Then link the form entries to the database. You have an unlimited amount of MySQL databases you can build in Bravenet.

I would recommend you utilize the Dreamweaver help functions to learn more about building a database driven website. If you are afraid to get into mysql then you could also look into setting everything up in a flat file using Spry. Dreamweaver has many spry functions that are not too difficult to set up.

Browser: Firefox

OS: XP

Re: Help with PHP script???

Jen,

You could create the same form using the Bravenet E-mail Form Builder and then copy and paste the code into your website.

This way you don't need to worry about any of the php coding.

Courtnie

Re: Help with PHP script???

I looked at that, but then I wasn't sure how to do it, or what it would look like...I mean would I be able to edit it so it matches the rest of my website? Or would I be stuck with those beige boxes and the like?

Browser: Firefox 3.5

OS: XP

Re: Help with PHP script???

Jen,

No, do not rename "pupquest.html" to "pupquest.php", as suggested. The page with the form, "pupquest.html", is suppose to be HTML. It doesn't need to be changed. There is nothing really dynamic about the page, except for the form validation script. And that isn't implemented correctly anyway. There was also no mention of storing the received data in a SQL data base. It sounded to me that all you wanted to do is receive the processed form data in a e-mail. You may want that eventually, but that is beyond this posting.

The "form" consists of all the fields between the starting and terminating "form" tags. When the "submit" button is clicked, all of the date from the various "input", "textarea", and "select" structures are passed to the script defined in the beginning form tag. In this case that would be the "pupquestform.php". That file is then responsible for receiving the data stream and stripping out all of the field names and the associated data. The PHP script then usually e-mails the data to the person defined in the script.

Right now the problem seems to be pointing to the form processing script, "pupquestform.php". I get a "file not found" error when I try to look at it. I assume it was there at one time, because you said you have already received e-mail from it. But that tends to point to a problem with the PHP coding. The data is always passed to the script but the script is responsible for extracting it correctly and sending it out. Maybe, if we could see the script, someone may be able to spot the error.

As Courtnie suggested, you could use Bravenet's email form service. Then you don't have to deal with PHP. You could use the same form and just change out the form tag at the top of the form. There would also be two extra hidden fields to add to the form that identify you to the form processor. The free service will allow up to 30 fields, so your form should work. At least with the free service, you can try it. If you don't like it, nothing lost. Note, Bravenet's email form service will send the processed form data to the email address you used to register with Bravenet.

Browser: Firefox, Netscape, Sea Monkey, Internet Explorer, .....

OS: Solaris (Sparc,x86), Linux, XP

Re: Help with PHP script???

Sure, here is the script. I think, unless I screwed up the php script that I told the form to look for is pupquestscript.php. I am trying to get it to email me the results. The point of the page is to have a user fill out the info so I can pre-screen them and have an idea what they are looking for in a puppy. I wanted the info to be sent to me in an email.


/* Subject and Email Varriables */

$emailSubject = 'Doberman Puppy Questionnaire';
$webMaster = 'exysdobes@gmail.com';

/* Gathering Data Variables */

$nameField = $_POST['name'];
$locationField = $_POST['location'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$referalfromField = $_POST['referalfrom'];
$livingconditionsField = $_POST['livingconditions'];
$maritalstatusField = $_POST['maritalstatus'];
$childrensagesField = $_POST['childrensages'];
$sexofpuppyField = $_POST['sexofpuppy'];
$puppycolourField = $_POST['puppycolour'];
$interestactivitiesField = $_POST['interestactivities'];
$previouslyowneddobeField = $_POST['previouslyowneddobe'];
$previousownexplainField = $_POST['previousownexplain'];
$ownotherpetsField = $_POST['ownotherpets'];
$otherpetsinfoField = $_POST['otherpetsinfo'];
$workorhomeField = $_POST['workorhome'];
$trainingclassesField = $_POST['trainingclasses'];
$responsiblepersonField = $_POST['responsibleperson'];
$commentsField = $_POST['comments'];

$body = <<




Name: $name

Location: $location

Email: $email

Phone: $phone

Referal from: $referalfrom

Living conditions: $livingconditions

Marital Status: $maritalstatus

Childrens ages: $childrensages

Sex of puppy: $sexofpuppy

Colour of puppy: $puppycolour

Interested activities: $interestactivities

Previously owned a Doberman: $previouslyowneddobe

Previously owned explaination: $previousownexplain

Owned other pets: $ownotherpets

Other pets info: $otherpetsinfo

Work home: $workorhome

Training classes: $trainingclasses

Responsible person for dog: $responsibleperson

Comments other info: $comments

EOD;


$headers = "From: $emailrn";
$headers .= "Content-type: text/htmlrn";
$success = mail($webMaster, $emailSubject, $body, $headers);


/* Results rendered as HTML */

$theResults = <<

Exys Registered Doberman Pinschers





Thank you for your interest in an Exys Registered Doberman Pinscher! Your email will be answered very soon!


 


 


 


 


 




EOD;
echo "$theResults";


?>

Browser: Firefox 3.5

OS: XP

Re: Help with PHP script???

Well, the forum made a mess of your PHP script, but I was able to extract it. Unless you know how, it's not a good idea to post code directly.

Everything looked pretty good, so I put it on my own site to see what it did. It worked mostly, except that the field listings didn't contain any data. Just like you indicated. I was kind of puzzled at first because it looked like you were doing everything right. But then I noticed the problem.

The problem is in your variable names. When you are collecting the form data you are using lines like the following lines.

Code:
<span style="font-weight:bold;">$nameField</span> = $_POST["name"];
<span style="font-weight:bold;">$locationField</span> = $_POST["location"];


But when you reference them later, you are using different variable names. The "_POST" extracts the data from the specified field, and assigns it to the variable on the left. In your "heredoc" string creation, you are using the field names, instead of the variable names. The names you are using are not defined variables and are therefore empty.

Code:
$body = <<<EOD
<br><hr><br>
Name: <span style="font-weight:bold;">$name</span> <br>
Location: <span style="font-weight:bold;">$location</span> <br>
EOD;


The sample code above contain the variable names and read as follows.

Code:
$body = <<<EOD
<br><hr><br>
Name: <span style="font-weight:bold;">$nameField</span> <br>
Location: <span style="font-weight:bold;">$locationField</span> <br>
EOD;


Fix all the variable references and your form will work fine. You may want to look into expanding it a little bit. There is no inherent protection built into the form and anyone can use it to spam the heck out of you. You need to add things like a check to see where the form was accessed. If it wasn't accessed from your site, you need to discard it. Or, a check to make sure all the important fields are filled out. You may want to take a look at Jack's FormMail.php. The script has a lot of built in features, that you can include. You can even replace your script with Jack's, but you may have to customize it for your use.

Browser: Firefox, Netscape, Sea Monkey, Internet Explorer, .....

OS: Solaris (Sparc,x86), Linux, XP

Re: Help with PHP script???

IT WORKED!!!!!!!!!!!!!!!!! You're brilliant! Thank you soooo much! I will look at that site and try to implement some of the things you mentioned in your post.

Thank you a million times over!

Browser: Firefox 3.5

OS: XP