PC Nerd Posted June 26, 2006 Share Posted June 26, 2006 Hey GuysI 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 More sharing options...
d_barszczak Posted June 26, 2006 Share Posted June 26, 2006 [!--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 More sharing options...
d_barszczak Posted June 26, 2006 Share Posted June 26, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.