Design Posted October 23, 2006 Share Posted October 23, 2006 I keep getting errors like unexpected T_Else from this script, and i'm not sure how to use case or switch statements with php... can someone please help me sort this error out? thanks in advance.[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>GSmash Tournament registration</title></head><body><?php// Check to make sure that the user isnt spamming people via the form:function spamcheck($field){ if(eregi("to:",$field) || eregi("cc:",$field)) { return TRUE; } else { return FALSE; }}function checkType($type){ if($_REQUEST['type1'] == TRUE AND $_REQUEST['type2'] == FALSE) { $type = "1"; } else if($_REQUEST['type1'] == FALSE and $REQUEST['type2'] == TRUE) { $type = "2"; } else { $type= "3"; } return $type; } //Make sure the form is filled out: if(isset($_REQUEST['email'])); { //check if the email address is invalid $mailcheck = spamcheck($_REQUEST['email']); if ($mailcheck==TRUE) { echo "Sorry, the e-mail you have entered is invalid, please re-enter it."; } else { //send email if the e-mail is valid $email = $_REQUEST['email']; $subject = "Smash Entry For: " . $_REQUEST['name']; $message = $_REQUEST['sname'] . ", " . $_REQUEST['char'] . ", " . checkType($type); mail("Linkmaster424@aol.com", "Subject: $subject", $message, "From: $email" ); echo "Thanks for your entry!Your data will be sent to the tournament staff."; } } else { echo "<h1 align='center'>Glenwood SSBM Tournament Form</h1><hr /><br /><h3 align='center'>Fill out the form and click the "Send" button.</h3>" echo "<form method='post' action='ssbm.php'> Email: <input type='text' name='email' /><br /> Name: <input type='text' name='name' /><br /> Smash Name: <input type='text' name='sname' max=4 min=1 size=16><br /> Character: <input type='text' name='char' /><br /> Entry Type(select at least one):<br /> One on One:<input type='checkbox' name='type1'><br /> Teams:<input type='checkbox' name='type2'><br /> </form>"; echo "<p><em>Note: In order to join the tournament, you will be required to pay an entry fee of $5.00 upon entry. This is mandatory for both teams and singles, meaning that if you are on a team, you AND your partner will need to pay the entry fee, totalling ten dollars. The same goes if you were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each tournament).</em></p><br /><p><font size='2'>©2006 By Tristan Nolan.</font></p>"}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/ Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 you are missing one closing '}' at teh end of that code (bewteen the echo statement and the '}') Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112894 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 :Dthx, i'll test it out again real fast Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112896 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 still getting this error:[quote]Parse error: syntax error, unexpected T_ELSE in /home/pc72/public_html/smash/Registration.php on line 58[/quote] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112898 Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 I see the problem...From the start of the checktype function you have an if statement at the end of whic you have return xxx. You will note the if statement finishes above the return and there is another closing brace immediately after - this is closing the function code block - decide what shoudl happen there and adjust the script accordingly. Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112903 Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 STrike that - just loaded it into my editor - it was just your nesting of code that threw me...There is a missing ';' at the end of teh last echo line. Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112905 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 fixed the missing ';' and still getting the error, and are you saying that i need to move the return line into the if statement? Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112911 Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 try this...[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>GSmash Tournament registration</title></head><body><?php// Check to make sure that the user isnt spamming people via the form:function spamcheck($field){ if ( eregi("to:", $field) || eregi("cc:", $field) || eregi(";", $field) ) { return true; } else { return false; }}function checkType($type){ if ( $_POST['type1'] == true && $_POST["type2"] == false ) { $type = 1; } elseif ( $_POST['type1'] == false && $_POST["type2"] == true ) { $type = 2; } else { $type= 3; } return $type;} //Make sure the form is filled out:if(isset($_POST['email']));{ //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ( (bool)$mailcheck == true) { echo "Sorry, the e-mail you have entered is invalid, please re-enter it."; } else { //send email if the e-mail is valid $email = $_POST['email']; $subject = "Smash Entry For: " . $_POST['name']; $type = checkType(); $message = $_POST['sname'] . ", " . $_POST['char'] . ", " . $type; mail("Linkmaster424@aol.com", "Subject: " . $subject, $message, "From: " . $email . "\r\n"); echo "Thanks for your entry!Your data will be sent to the tournament staff."; }} else{?> <h1 align="center">Glenwood SSBM Tournament Form</h1> <hr /> <br /> <h3 align="center">Fill out the form and click the "Send" button.</h3> <form method="post" action="ssbm.php"> Email: <input type="text" name="email" /><br /> Name: <input type="text" name="name" /><br /> Smash Name: <input type="text" name="sname" max=4 min=1 size=16><br /> Character: <input type="text" name="char" /><br /> Entry Type(select at least one):<br /> One on One:<input type="checkbox" name="type1"><br /> Teams:<input type="checkbox" name="type2"><br /> </form> <p><em>Note: In order to join the tournament, you will be required to pay an entry fee of $5.00 upon entry. This is mandatory for both teams and singles, meaning that if you are on a team, you AND your partner will need to pay the entry fee, totalling ten dollars. The same goes if you were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each tournament).</em></p> <br /> <p><font size="2">©2006 By Tristan Nolan.</font></p><?php}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112931 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 Now I'm getting this error:[code]Parse error: syntax error, unexpected T_ELSE in /home/pc72/public_html/smash/Test.php on line 73[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112933 Share on other sites More sharing options...
ToonMariner Posted October 23, 2006 Share Posted October 23, 2006 D'OHthe is an ';' rigth after if(isset($_POST['email'])); !!! I missed that! take it out.Just looked at your code and spotted something that will save you some headaches...You have the check type function to check which type was set... but if you look at the logic and your html you will notice that the user coudl check bothboxes or neither which would set type to 3 - be careful with that!!! If you only want them to be able to slect one I suggest you change to radio buttons.... Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112935 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 Teh checkboxes are meant to allow them to check both at once, however you pointed out that they can check neither, thanks much, i missed a handler for that situation :-DAside from that, I'm now getting this error when I try to run the script:[quote]Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/pc72/public_html/smash/Test.php on line 52[/quote]And here's what my code looks like right now(after all above changes):[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>GSmash Tournament registration</title></head><body><?php// Check to make sure that the user isnt spamming people via the form:function spamcheck($field){ if ( eregi("to:", $field) || eregi("cc:", $field) || eregi(";", $field) ) { return true; } else { return false; }}function checkType($type){ if ( $_POST['type1'] == true && $_POST["type2"] == false ) { $type = 1; } elseif ( $_POST['type1'] == false && $_POST["type2"] == true ) { $type = 2; } elseif ( $_POST['type1'] == false && $_POST['type2'] == false ) { echo "<font color="red">ERROR: You must select a tournament type.</font>" } else { $type= 3; } return $type;} //Make sure the form is filled out:if(isset($_POST['email'])){ //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ( (bool)$mailcheck == true) { echo "Sorry, the e-mail you have entered is invalid, please re-enter it."; } else { //send email if the e-mail is valid $email = $_POST['email']; $subject = "Smash Entry For: " . $_POST['name']; $type = checkType(); $message = $_POST['sname'] . ", " . $_POST['char'] . ", " . $type; mail("Linkmaster424@aol.com", "Subject: " . $subject, $message, "From: " . $email . "\r\n"); echo "Thanks for your entry!Your data will be sent to the tournament staff."; }} else{?> <h1 align="center">Glenwood SSBM Tournament Form</h1> <hr /> <br /> <h3 align="center">Fill out the form and click the "Send" button.</h3> <form method="post" action="ssbm.php"> Email: <input type="text" name="email" /><br /> Name: <input type="text" name="name" /><br /> Smash Name: <input type="text" name="sname" max=4 min=1 size=16><br /> Character: <input type="text" name="char" /><br /> Entry Type(select at least one):<br /> One on One:<input type="checkbox" name="type1"><br /> Teams:<input type="checkbox" name="type2"><br /> </form> <p><em>Note: In order to join the tournament, you will be required to pay an entry fee of $5.00 upon entry. This is mandatory for both teams and singles, meaning that if you are on a team, you AND your partner will need to pay the entry fee, totalling ten dollars. The same goes if you were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each tournament).</em></p> <br /> <p><font size="2">©2006 By Tristan Nolan.</font></p><?php}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-112940 Share on other sites More sharing options...
mikc Posted October 23, 2006 Share Posted October 23, 2006 [quote author=Design link=topic=112380.msg456093#msg456093 date=1161568437]Teh checkboxes are meant to allow them to check both at once, however you pointed out that they can check neither, thanks much, i missed a handler for that situation :-DAside from that, I'm now getting this error when I try to run the script:[quote]Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/pc72/public_html/smash/Test.php on line 52[/quote]And here's what my code looks like right now(after all above changes):[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>GSmash Tournament registration</title></head><body><?php// Check to make sure that the user isnt spamming people via the form:function spamcheck($field){ if ( eregi("to:", $field) || eregi("cc:", $field) || eregi(";", $field) ) { return true; } else { return false; }}function checkType($type){ if ( $_POST['type1'] == true && $_POST["type2"] == false ) { $type = 1; } elseif ( $_POST['type1'] == false && $_POST["type2"] == true ) { $type = 2; } elseif ( $_POST['type1'] == false && $_POST['type2'] == false ) { echo "<font color="red">ERROR: You must select a tournament type.</font>" } else { $type= 3; } return $type;} //Make sure the form is filled out:if(isset($_POST['email'])){ //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ( (bool)$mailcheck == true) { echo "Sorry, the e-mail you have entered is invalid, please re-enter it."; } else { //send email if the e-mail is valid $email = $_POST['email']; $subject = "Smash Entry For: " . $_POST['name']; $type = checkType(); $message = $_POST['sname'] . ", " . $_POST['char'] . ", " . $type; mail("Linkmaster424@aol.com", "Subject: " . $subject, $message, "From: " . $email . "\r\n"); echo "Thanks for your entry!Your data will be sent to the tournament staff."; }} else{?> <h1 align="center">Glenwood SSBM Tournament Form</h1> <hr /> <br /> <h3 align="center">Fill out the form and click the "Send" button.</h3> <form method="post" action="ssbm.php"> Email: <input type="text" name="email" /><br /> Name: <input type="text" name="name" /><br /> Smash Name: <input type="text" name="sname" max=4 min=1 size=16><br /> Character: <input type="text" name="char" /><br /> Entry Type(select at least one):<br /> One on One:<input type="checkbox" name="type1"><br /> Teams:<input type="checkbox" name="type2"><br /> </form> <p><em>Note: In order to join the tournament, you will be required to pay an entry fee of $5.00 upon entry. This is mandatory for both teams and singles, meaning that if you are on a team, you AND your partner will need to pay the entry fee, totalling ten dollars. The same goes if you were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each tournament).</em></p> <br /> <p><font size="2">©2006 By Tristan Nolan.</font></p><?php}?></body></html>[/code][/quote]this should work you forgot a semicolon[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>GSmash Tournament registration</title></head><body><?php// Check to make sure that the user isnt spamming people via the form:function spamcheck($field){ if ( eregi("to:", $field) || eregi("cc:", $field) || eregi(";", $field) ) { return true; } else { return false; }}function checkType($type){ if ( $_POST['type1'] == true && $_POST["type2"] == false ) { $type = 1; } elseif ( $_POST['type1'] == false && $_POST["type2"] == true ) { $type = 2; } elseif ( $_POST['type1'] == false && $_POST['type2'] == false ) { echo "<font color="red">ERROR: You must select a tournament type.</font>"; } else { $type= 3; } return $type;} //Make sure the form is filled out:if(isset($_POST['email'])){ //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ( (bool)$mailcheck == true) { echo "Sorry, the e-mail you have entered is invalid, please re-enter it."; } else { //send email if the e-mail is valid $email = $_POST['email']; $subject = "Smash Entry For: " . $_POST['name']; $type = checkType(); $message = $_POST['sname'] . ", " . $_POST['char'] . ", " . $type; mail("Linkmaster424@aol.com", "Subject: " . $subject, $message, "From: " . $email . "\r\n"); echo "Thanks for your entry!Your data will be sent to the tournament staff."; }} else{?> <h1 align="center">Glenwood SSBM Tournament Form</h1> <hr /> <br /> <h3 align="center">Fill out the form and click the "Send" button.</h3> <form method="post" action="ssbm.php"> Email: <input type="text" name="email" /><br /> Name: <input type="text" name="name" /><br /> Smash Name: <input type="text" name="sname" max=4 min=1 size=16><br /> Character: <input type="text" name="char" /><br /> Entry Type(select at least one):<br /> One on One:<input type="checkbox" name="type1"><br /> Teams:<input type="checkbox" name="type2"><br /> </form> <p><em>Note: In order to join the tournament, you will be required to pay an entry fee of $5.00 upon entry. This is mandatory for both teams and singles, meaning that if you are on a team, you AND your partner will need to pay the entry fee, totalling ten dollars. The same goes if you were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each tournament).</em></p> <br /> <p><font size="2">©2006 By Tristan Nolan.</font></p><?php}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113085 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 Now I've got this error :([code]Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/pc72/public_html/smash/Test.php on line 52[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113173 Share on other sites More sharing options...
KevinM1 Posted October 23, 2006 Share Posted October 23, 2006 The error stems from you using double quotes to both echo output and to set a font color on that line. If you use double quotes for output, you need to use single quotes for HTML tags that you set properties on within that output. Try the following and see if it works:[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>GSmash Tournament registration</title></head><body><?php// Check to make sure that the user isnt spamming people via the form:function spamcheck($field){ if(eregi("to:", $field) || eregi("cc:", $field) || eregi(";", $field)){ return true; } else{ return false; }}function checkType($type){ if($_POST['type1'] == true && $_POST['type2'] == false){ $type = 1; } elseif($_POST['type1'] == false && $_POST['type2'] == true){ $type = 2; } elseif($_POST['type1'] == false && $_POST['type2'] == false){ echo "<font color='red'>ERROR: You must select a tournament type.</font>"; } else{ $type = 3; }return $type;}//Make sure the form is filled out:if(isset($_POST['email'])){ //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if((bool)$mailcheck == true){ echo "Sorry, the e-mail you have entered is invalid, please re-enter it."; } else{ //send email if the e-mail is valid $email = $_POST['email']; $subject = "Smash Entry For: " . $_POST['name']; $type = checkType(); $message = $_POST['sname'] . ", " . $_POST['char'] . ", " . $type; mail("Linkmaster424@aol.com", "Subject: " . $subject, $message, "From: " . $email . "\r\n"); echo "Thanks for your entry! Your data will be sent to the tournament staff."; }} else{?> <h1 align="center">Glenwood SSBM Tournament Form</h1> <hr /> <br /> <h3 align="center">Fill out the form and click the "Send" button.</h3> <form method="post" action="ssbm.php"> Email: <input type="text" name="email" /><br /> Name: <input type="text" name="name" /><br /> Smash Name: <input type="text" name="sname" max=4 min=1 size=16><br /> Character: <input type="text" name="char" /><br /> Entry Type(select at least one):<br /> One on One:<input type="checkbox" name="type1"><br /> Teams:<input type="checkbox" name="type2"><br /> </form> <p><em>Note: In order to join the tournament, you will be required to pay an entry fee of $5.00 upon entry. This is mandatory for both teams and singles, meaning that if you are on a team, you AND your partner will need to pay the entry fee, totalling ten dollars. The same goes if you were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each tournament).</em></p> <br /> <p><font size="2">©2006 By Tristan Nolan.</font></p><?php}?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113190 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 OMG, IT WORKS!! :Dty ty ty Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113265 Share on other sites More sharing options...
Design Posted October 23, 2006 Author Share Posted October 23, 2006 wait... not so fastit loads the page fine, but when i try to submit data through the form, it doesnt email me, but instead displays this message:[quote]Warning: Missing argument 1 for checktype() in /home/pc72/public_html/smash/Index.php on line 21[/quotemore help needed.. lol Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113358 Share on other sites More sharing options...
KevinM1 Posted October 23, 2006 Share Posted October 23, 2006 You have a logic problem.You originally define the function checkType as one that takes one argument:[code]<?phpfunction checkType($type){ if($_POST['type1'] == true && $_POST['type2'] == false){ $type = 1; } elseif($_POST['type1'] == false && $_POST['type2'] == true){ $type = 2; } elseif($_POST['type1'] == false && $_POST['type2'] == false){ echo "<font color='red'>ERROR: You must select a tournament type.</font>"; } else{ $type = 3; }return $type;}?>[/code]But when you use it, you don't pass it an argument (line 54):[code]<?php$type = checkType();?>[/code]With the way you have your function defined, you don't really use the argument to pass to it, so try using:[code]<?phpfunction checkType(){ if($_POST['type1'] == true && $_POST['type2'] == false){ $type = 1; } elseif($_POST['type1'] == false && $_POST['type2'] == true){ $type = 2; } elseif($_POST['type1'] == false && $_POST['type2'] == false){ echo "<font color='red'>ERROR: You must select a tournament type.</font>"; } else{ $type = 3; }return $type;}?>[/code] Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113373 Share on other sites More sharing options...
Design Posted October 24, 2006 Author Share Posted October 24, 2006 :D I think you nailed itHowever, it's not e-mailing it to me when i submit the form, no error being displayed, but yeah.also, what code would I use to make a back button appear on the page after a successful registration occurs? Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113431 Share on other sites More sharing options...
Design Posted October 24, 2006 Author Share Posted October 24, 2006 still not mailing the info, can someone plz help? Link to comment https://forums.phpfreaks.com/topic/24787-help-sorting-out-my-if-and-else-statements/#findComment-113840 Share on other sites More sharing options...
Recommended Posts