Forum Moderators: coopster

Message Too Old, No Replies

PHP form variables not showin up..?

         

Christian SEO

2:30 am on Apr 4, 2003 (gmt 0)

10+ Year Member



I'm just trying to take form input and format that data into an email.

I get the email, I see the field headers, but no data. The email comes to me and looks like this:

Requested by:
Address:
City:
State:
Zip:
Email:

Here's a short version of that process:

(?php

//Declare the variables
$address = "";

//Get the contents of form
$address = $_POST['address'];

//mail() function sends the mail
mail($to,$subject, "Revision request submitted on $today\n
\n
Address: $address");

?)

I started with a sample script that I downloaded and did get it to work, but this new version doesn't and I'm not seeing what the heck is different!

Thanks,
Christian

DrDoc

6:42 am on Apr 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, the problem seems to be that register_globals is on.

What happens is that when you "declare" the variable, you in fact reset it.

Try taking these lines out.

//Declare the variables
$address = "";

//Get the contents of form
$address = $_POST['address'];

:)

Christian SEO

7:11 am on Apr 4, 2003 (gmt 0)

10+ Year Member



I tried it by taking both sections out, but that is what I had to start with and it still does not work.

That is why I added the Declarations..

The first should resent and initialize, which I didn't think is really needed, because the loading of the variables with the

$address = $_POST['address'];

Adding this in the sample script I was able to get it to work. It was the move to the production script that is driving me crazy... I know it's something simple. Here's all of what I have:

<?php
//Declare the variables
//$by = "";
//$address = "";
//$city = "";
//$state = "";
//$zip = "";
//$email = "";
//$comments = "";
$today = date("F j, Y, g:i a");

//Get the contents of form
$by = $_POST['by'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$comments = $_POST['comments'];

//*********************************************************
//** Message to site owner ******************************
//*********************************************************
$message = "Revision request submitted on $today\n
\n
Requested by: $by\n
Address: $address\n
City: $city\n
State: $state\n
Zip: $zip\n
Email: $email\n
\n
Comments: $comments \n";
//=========================================================

$to = "name@domain.com";
$from = "name@domain.com"; //use in case sender email bad
//$to = "name@domain.com";
//$from = "name@domain.com"; //use in case sender email bad
$subject = "Revision Request - $today";
//========================================================

//mail() function sends the mail
mail($to,$subject, "Revision request submitted on $today\n
\n
Requested by: $by\n
Address: $ADDRESS\n
City: $CITY\n
State: $STATE\n
Zip: $ZIP\n
Email: $EMAIL\n
\n
Comments: $comments \n");
//========================================================

print "done!";
?>

When the script executes, I do see the "Done!" in the browser.

Thanks a lot for your help!
Christian

andreasfriedrich

7:19 am on Apr 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Variable names are case sensitive. $address and $ADDRESS are not the same. In your code only $address will contain the submitted address. $ADDRESS will be empty. That is why you get an email with no values filled in.

Andreas

Christian SEO

7:36 am on Apr 4, 2003 (gmt 0)

10+ Year Member



I thought about that too, but you'll notice that the variable "by" is consistantly in lowercase.

And I did now change them all to lowercase with the same results....

I do appreciate the help...
Christian

Allen

7:46 am on Apr 4, 2003 (gmt 0)

10+ Year Member



what do you get if you put:

echo "<PRE>_POST: ";
print_r ($_POST);
echo "</PRE>";

at the top of the script?

You could also try putting:

echo "By: ". $by;

before the:

$by = "";

Also, I note that you've used (?php instead of <?php . Is this just to make sure it shows up on the forums?

Allen

andreasfriedrich

7:49 am on Apr 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try just echo [php.net]ing $_POST['by']; to test whether any data gets actually submitted?

Andreas

DrDoc

7:52 am on Apr 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And the script is called using POST?

Try taking this whole section out:
$by = $_POST['by'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$comments = $_POST['comments'];

Christian SEO

2:49 pm on Apr 4, 2003 (gmt 0)

10+ Year Member



We have a solution!

Allen: I added the following code that you mentioned.

echo "<PRE>_POST: ";
print_r ($_POST);
echo "</PRE>";

at the top of the script. Here is the output:

_POST: Array
(
[RECIPIENT] => name@n.com
[SUBJECT] => Request An Appraisal
[BY] => wer
[ADDRESS] => wer
[CITY] => wer
[STATE] => FL
[ZIP] => wer
[EMAIL] => sales@n.com
[COMMENTS] => dfgdfg
[Submit] => Submit
)
done!

It still took me a few minutes, but I then noticed that the variable names are coming in in UPPER CASE!

I changed the script to upper case and it's working!

Thanks to all that contributed and helped with this problem, I spent most of yesterday trying to use the PHP help and trying everything I knew to figure it out. ONce again, it's one of those stinking little details that kills me.

While I enjoy this, it's why I don't do it for a living...!

Thanks again,
Christian

P.S. If anyone has SEO questions, please let me know.