Jump to content


Photo

Emailing Form input


  • Please log in to reply
2 replies to this topic

#1 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 26 June 2006 - 08:57 AM


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);

?>


#2 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 26 June 2006 - 09:10 AM

[!--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) View Post[/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.

When all else fails - Try reading the manual.

Integrated IT Systems Ltd


#3 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 26 June 2006 - 09:28 AM

On Second thoughts i prob would have used a switch statement instead.


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;
}



When all else fails - Try reading the manual.

Integrated IT Systems Ltd





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users