pcw Posted June 26, 2009 Share Posted June 26, 2009 Hi, I have got the following script: if ($_POST['userMail'] == true) { header( 'Location: emailForm.php' ); } elseif ($_POST['subjectField'] == true) { header('Location: emailForm.php?cmd=form2'); } elseif ($_POST['message'] == true) { header('Location: emailForm.php?cmd=form3'); } elseif (($_POST['userMail'] == true) && ($_POST['subjectField'] == true)); { header('Location: emailForm.php?cmd=form4'); } elseif ((($_POST['userMail'] == true) && ($_POST['subjectField'] == true) && ($_POST['message'] == true))); { header('Location: emailForm.php?cmd=form5'); } But I keep getting an error and cant figure out how to fix it. Any help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/ Share on other sites More sharing options...
Maq Posted June 26, 2009 Share Posted June 26, 2009 Can you post the entire error? Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864213 Share on other sites More sharing options...
pcw Posted June 26, 2009 Author Share Posted June 26, 2009 Parse error: syntax error, unexpected T_ELSEIF in /home/buildit/public_html/email/emailSetup.php on line 300 It says line 300 because this script is between the case and break tags. Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864215 Share on other sites More sharing options...
Maq Posted June 26, 2009 Share Posted June 26, 2009 Remove this semi-colon: elseif (($_POST['userMail'] == true) && ($_POST['subjectField'] == true)); Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864217 Share on other sites More sharing options...
pkedpker Posted June 26, 2009 Share Posted June 26, 2009 yes remove semi-colons FROM ELSEIF/IF statements from all of them wouldn't hurt to indent too looks ugly atm edit: fixed yah u dont even need brackets since they are 1 liners anyways Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864221 Share on other sites More sharing options...
Maq Posted June 26, 2009 Share Posted June 26, 2009 yes remove semi-colons from all of them wouldn't hurt to indent too looks ugly atm No, just remove the semi-colons after the if/elseif statements. You should also indent everything in the blocks like you mentioned. Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864223 Share on other sites More sharing options...
pcw Posted June 26, 2009 Author Share Posted June 26, 2009 Ok, thanks for your replies, that fixed it. The only thing is, when the checkboxes are ticked on the form on the previous page, it always redirects to emailForm.php?cmd=form5, even when it really should redirect to form 1,2,3 or 4. Here is the code for both pages. case "setup3": $sendmail_from = $_POST['sendmail_from']; $subject = $_POST['subject']; $default = $_POST['default']; echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Sitebuilder - PHP Email Script</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #333333; } .style1 {color: #CCCCFF} .style2 { font-size: 24px; font-weight: bold; } .style3 {color: #9999FF} .style4 {color: #FFFFCC} --> </style></head> <body> <div id="header" style="position:absolute; left:4px; top:3px; width:1000px; height:99px; z-index:1; background-color: #666666; layer-background-color: #666666; border: 1px none #000000;"> <div align="center" class="style1"> <pre class="style2">Sitebuilder</pre> <pre><strong>PHP Email script </strong></pre> </div> </div> <div id="Layer1" style="position:absolute; left:4px; top:109px; width:1000px; height:430px; z-index:3"> <h2 align="center" class="style4"> PHP Email Script </h2> <blockquote> <form action=emailSetup.php?cmd=setup4 method=POST> <input type=hidden name=agree value=true>'; echo "<input type=hidden name=sendmail_from value=$sendmail_from>"; echo "<input type=hidden name=subject value=$subject>"; echo "<input type=hidden name=default value=$default>"; echo ' <table border=0 align=center> <tr><td colspan=2> <tr><td colspan=2 class=style1><b><center>EMAIL SETTINGS</center></b></td></tr> <tr><td colspan=2><p class=style4>Please select which fields you would like the user to complete when sending a message:</p></td></tr> <tr><td class=style1>Mail From:</td><td><input type=checkbox name=userMail></td></tr> <tr><td class=style1>Subject:</td><td><input type=checkbox name=subjectField></td></tr> <tr><td class=style1>Message:</td><td><input type=checkbox name=message></td></tr> <tr><td colspan=2><input type=submit name=submit value=submit></td></tr> </table> </form> </blockquote> </div> </body> </html> '; break; case "setup4": $sendmail_from = $_POST['sendmail_from']; $subject = $_POST['subject']; $default = $_POST['default']; $userMail = $_POST['userMail']; $subjectField = $_POST['subjectField']; $filename = "emailAdmin.php"; $fa = fopen( $filename, "w" ) or die("Error opening $filename"); fwrite( $fa, "<?php\n \$data[0]['sendmail_from'] = '$sendmail_from';\n \$data[0]['subject'] = '$subject';\n \$data[0]['default'] = '$default';\n \$data[0]['userMail'] = '$userMail';\n \$data[0]['subjectField'] = '$subjectField';\n?>" ); fclose( $fa ); if ($_POST['userMail'] == true) { header( 'Location: emailForm.php' ); } elseif ($_POST['subjectField'] == true) { header('Location: emailForm.php?cmd=form2'); } elseif ($_POST['message'] == true) { header('Location: emailForm.php?cmd=form3'); } elseif (($_POST['userMail'] == true) && ($_POST['subjectField'] == true)) { header('Location: emailForm.php?cmd=form4'); } elseif ((($_POST['userMail'] == true) && ($_POST['subjectField'] == true) && ($_POST['message'] == true))); { header('Location: emailForm.php?cmd=form5'); } break; Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864231 Share on other sites More sharing options...
pkedpker Posted June 26, 2009 Share Posted June 26, 2009 in fwrite many n's no reason.. also <?phpn ? that normal.. must be <?php no n's also case "setup4": ??no switch?? whats up with that.. maybe you mean $_GET['setup4']; nevermind about switch question.. you must not posted all code.. but elseif goes to end because all above failed.. to evalute because all true at all times.. try this if ($_POST['userMail'] == true) to if (isset($_POST['userMail'])) elseif ($_POST['subjectField'] == true) to elseif (isset($_POST['userMail'])) To this to all i can't do it all for you.. try yourself to all IF ELSE use isset.. and remove true.. because it already check if true.. no need to put it waste memory.. Quote Link to comment https://forums.phpfreaks.com/topic/163790-unexpected-t_elseif/#findComment-864262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.