Click to See Complete Forum and Search --> : PHP form handler


billt
06-01-2006, 05:05 AM
ok I am working with a type of feedback forms for my users to submit info to me and i can get it in my email box. problem is when i try this i get the following error.

Parse error: syntax error, unexpected T_VARIABLE in /home/.caty/overlordofevil/overlordofeviltest.nerowisconsin.com/newmember.php on line 19

I believe the problem is because i am trying to have multiple variables sent in the msg section of the email.

Here is a copy of the code I am using.
******************************************************
<?php

$Name = $_POST['Name'];
$address = $_POST['address'];
$cityandstate = $_POST['cityandstate'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$dob = $_POST['dob'];
$Email = $_POST['Email'];
$advertisement = $_POST['advertisement'];
$other = $_POST['other'];
$username = $_POST['username'];
$password = $_POST['password'];



$to = "newmember@nerowisconsin.com";
$re = "New Member Sign Up";
$msg = "Name - "$Name\n"address - "$address\n"City and State - "$cityandstate\n"Zip Code - "$zip\n"Phone Number - "$phone\n"Date of Birth - "$dob\n"E-mail - "$Email\n"How did you hear - "$advertisement\n"Other source - "$other\n\n\n"Username - "$username\n"Password - "$password;

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html;";
$headers .= " charset=iso-8859-1\r\n";
$headers .= "From: $Email \r\n";
$headers .= "Cc: $Email \r\n";
mail( $to, $re, $msg, $headers );
?>
******************************************************
Now what I would like to do is to take all the variables(fields) from my form and get them to send. Not sure how to do this and I am unsure if php can handle what I would like to do. I think i coded it correctly or I may be completely off so any hints or assistance that is offered would be appreciated.

Thanks
Bill

felgall
06-01-2006, 05:22 AM
$msg = "Name - "$Name\n"address - "$address\n"City and State - "$cityandstate\n"Zip Code - "$zip\n"Phone Number - "$phone\n"Date of Birth - "$dob\n"E-mail - "$Email\n"How did you hear - "$advertisement\n"Other source - "$other\n\n\n"Username - "$username\n"Password - "$password;

Translates as

$msg = "Name - " garbage that PHP doesn't understand.

If that second " is supposed to be the end of the text then it needs to be followed by a ; or a .
If it is part of the content then it needs to be preceded by a \
The same applies to the following "s

billt
06-01-2006, 06:09 AM
ok i figured it was garbage i just was unsure of the format for it. thanks..

the $msg = "Name - " part is not needed. I was trying to put a label on the variable to make it easier to read in the email. so if i remove all of the labels. I figure the code should look like this.

$msg = $Name\n$address\n$cityandstate\n$zip\n$phone\n$dob\n$Email\n $advertisement\n$other\n\n\n$username\n$password;

Now I tried it like this and i get

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/.caty/overlordofevil/overlordofeviltest.nerowisconsin.com/newmember.php on line 19

Parse error: syntax error, unexpected T_STRING in /home/.caty/overlordofevil/overlordofeviltest.nerowisconsin.com/newmember.php on line 19

I am not sure how else to codethis statement. I have removed the \n , i have tried a . or a ; after each variable but i still get a unexpected T_VARIABLE message.

I am new to using php so i am unsure what else to do. I am writing these pages to learn and get better at programing so agian any help is appreciated.

Thanks
Bill

NogDog
06-01-2006, 09:25 AM
Either of these two formats will be functionaly equivalent:

// double-quotes:
$msg = "$Name\n$address\n$cityandstate\n$zip\n$phone\n$dob\n$Email\n $advertisement\n$other\n\n\n$username\n$password";

// "heredoc" method:
$msg = <<<EOD
$Name
$address
$cityandstate
$zip
$phone
$dob
$Email
$advertisement
$other


$username
$password;
EOD;

You can include literal text with the variables in either type of string, for example:

$msg = <<<EOD
Name: $Name
Address: $address
City/State: $cityandstate
etc....
EOD;