Jump to content

Help sorting out my if{} and else{} statements


Design

Recommended Posts

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 &quot;Send&quot; 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 &nbsp; &nbsp; $5.00 upon entry. &nbsp;This is mandatory for both teams and singles, meaning that if you are on a team, &nbsp;you AND your partner will need to pay the entry fee, totalling ten dollars. &nbsp;The same goes if you &nbsp;were to enter in both tournaments, you would have to pay a fee of ten dollars(five for each &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tournament).</em></p><br /><p><font size='2'>&copy;2006 By Tristan Nolan.</font></p>"
}
?>
</body>
</html>
[/code]
Link to comment
Share on other sites

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
Share on other sites

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 &quot;Send&quot; 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 &nbsp; &nbsp; $5.00 upon entry. &nbsp;This is mandatory for both teams and singles,
meaning that if you are on a team, &nbsp;you AND your partner will need to pay the entry fee,
totalling ten dollars. &nbsp;The same goes if you &nbsp;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">&copy;2006 By Tristan Nolan.</font></p>
<?php
}
?>
</body>
</html>[/code]

Link to comment
Share on other sites

D'OH

the 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
Share on other sites

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 :-D

Aside 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 &quot;Send&quot; 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 &nbsp; &nbsp; $5.00 upon entry. &nbsp;This is mandatory for both teams and singles,
meaning that if you are on a team, &nbsp;you AND your partner will need to pay the entry fee,
totalling ten dollars. &nbsp;The same goes if you &nbsp;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">&copy;2006 By Tristan Nolan.</font></p>
<?php
}
?>
</body>
</html>
[/code]
Link to comment
Share on other sites

[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 :-D

Aside 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 &quot;Send&quot; 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 &nbsp; &nbsp; $5.00 upon entry. &nbsp;This is mandatory for both teams and singles,
meaning that if you are on a team, &nbsp;you AND your partner will need to pay the entry fee,
totalling ten dollars. &nbsp;The same goes if you &nbsp;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">&copy;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 &quot;Send&quot; 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 &nbsp; &nbsp; $5.00 upon entry. &nbsp;This is mandatory for both teams and singles,
meaning that if you are on a team, &nbsp;you AND your partner will need to pay the entry fee,
totalling ten dollars. &nbsp;The same goes if you &nbsp;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">&copy;2006 By Tristan Nolan.</font></p>
<?php
}
?>
</body>
</html>
[/code]
Link to comment
Share on other sites

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 &quot;Send&quot; 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. &nbsp;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. &nbsp;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">&copy;2006 By Tristan Nolan.</font></p>

<?php
}
?>
</body>
</html>
[/code]
Link to comment
Share on other sites

wait... not so fast
it 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[/quote

more help needed.. lol
Link to comment
Share on other sites

You have a logic problem.

You originally define the function checkType as one that takes one argument:

[code]
<?php
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;
}
?>
[/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]
<?php
function 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
Share on other sites

:D I think you nailed it

However, 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
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.