Jump to content

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

?>
Link to comment
https://forums.phpfreaks.com/topic/12917-emailing-form-input/
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.
Link to comment
https://forums.phpfreaks.com/topic/12917-emailing-form-input/#findComment-49586
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]
Link to comment
https://forums.phpfreaks.com/topic/12917-emailing-form-input/#findComment-49588
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.