Jump to content

Archived

This topic is now archived and is closed to further replies.

PC Nerd

Emailing Form input

Recommended Posts


Hey Guys

I am working on a form that will email form input to my email, and later write it to a database. The input from a select feild in HTML is numbered 0-6, and i want to convert it to a longer string, eg an actual age range. When i use the if statement to do this, PHP says theres a parse error unexpected T_IF error. Can anyone help me.

MY CODE:


<?php

$newLine = "/n"


if($_POST['Age'] == "1"){$Age = "Younger than 13";}

elseif ($_POST[Age] == "3"){$Age = "13 - 18";}

else if ($_POST[Age] == "4"){$Age = "19 - 25";}

else if ($_POST[Age] == "5"){$Age = "26 - 35";}

else if ($_POST[Age] == "6"){$Age = "36 - 50";}

else{pass}



$mailaddress = "EMAIL EXCLUDED"
$Subject = "Form Input Email"
$message = "$_POST[First_Name] $_POST[Last_Name]"

$message = $message.$newLine
$message = $message.$_POST[Email]
$message = $message.$newLine
$message = $message.$newLine
$message = $message.$_POST[Age]
$message = $message.$newLine
$message = $message.$_POST[reason]

$header = " Form Input Email"



mail($mailaddress,$subject,$message,$header);

?>

Share this post


Link to post
Share on other sites
[!--quoteo(post=387973:date=Jun 26 2006, 09:57 AM:name=PC NErd)--][div class=\'quotetop\']QUOTE(PC NErd @ Jun 26 2006, 09:57 AM) [snapback]387973[/snapback][/div][div class=\'quotemain\'][!--quotec--]
if($_POST['Age'] == "1"){$Age = "Younger than 13";}

elseif ($_POST[Age] == "3"){$Age = "13 - 18";}

else if ($_POST[Age] == "4"){$Age = "19 - 25";}

else if ($_POST[Age] == "5"){$Age = "26 - 35";}

else if ($_POST[Age] == "6"){$Age = "36 - 50";}

else{pass}
$mailaddress = "EMAIL EXCLUDED"
$Subject = "Form Input Email"
$message = "$_POST[First_Name] $_POST[Last_Name]"

$message = $message.$newLine
$message = $message.$_POST[Email]
$message = $message.$newLine
$message = $message.$newLine
$message = $message.$_POST[Age]
$message = $message.$newLine
$message = $message.$_POST[reason]

$header = " Form Input Email"
mail($mailaddress,$subject,$message,$header);

?>
[/quote]

Think your problem might be that your first statment is a correct elseif and the rest are incorrect else if. The space makes it a different statement.

Share this post


Link to post
Share on other sites
On Second thoughts i prob would have used a switch statement instead.

[code]

switch ($_POST['Age']) {

case "1":
$Age = "Younger than 13";
break;

case "2":
$Age = "13 - 18";
break;

case "3":
$Age = "19 - 25";
break;

case "4":
$Age = "26 - 35";
break;

case "5":
$Age = "36 - 50";
break;

default:
break;
}


[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.