Jump to content


Photo

PHP if statement


  • Please log in to reply
9 replies to this topic

#1 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 27 June 2006 - 08:54 AM

Hey guys

im still having trouble with my if statements. im writing a script which checks form input. When i check the emails confirmation, php tells me that there is an unexpected "}". this is the closing curly brace for my if loop



can anyone help me......


My code is


if($_POST[Email] != $_POST[Email-confirm])
{
echo "Your Email was not correctly confirmed, please make sure that you enter the same Email in both fields.<br><br>";
}

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 June 2006 - 09:13 AM

Can you post the code for the for loop. As the code you have provided is fine.

Also make sure you place apostrophes ' around your indexes for your arrays like so:
if($_POST['Email'] != $_POST['Email-confirm'])


#3 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 27 June 2006 - 09:17 AM

[!--quoteo(post=388416:date=Jun 27 2006, 07:13 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 27 2006, 07:13 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Can you post the code for the for loop. As the code you have provided is fine.

Also make sure you place apostrophes ' around your indexes for your arrays like so:
if($_POST['Email'] != $_POST['Email-confirm'])
[/quote]


thanks, ill give it a go

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 June 2006 - 09:18 AM

No thats not the solution! I need you to post your for loop code here.

#5 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 27 June 2006 - 09:19 AM

i tried it and it didnt work. the error is:

Parse error: syntax error, unexpected '}' in /WEB SITE/public_html/game/Email_Sender.php on line 30

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 June 2006 - 09:44 AM

I told you twice! POST the code for your forl oop! The bit I told you to change was just a suggestion, it wasnt a soloution.

#7 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 27 June 2006 - 09:51 AM

Fine, but it wont help.

<?php

$newLine = "/n";

echo "The infomation you entered is as follows.  If it is incorrect, please re enter the information <a href = 'Emails.php'>here</a><br><br>";


foreach($_POST as $field => $value){
if(empty($_POST[$field])){

echo "You left the <font color = 'red'>$field</font> field empty.  If you want to submit the request please go back and fill in this field,  <br><br>";

echo "<a href = 'Emails.php'>click here to restart request</a>";
echo "<br><br>";
}


else{

continue;
}
}


if($_POST['Email'] != $_POST['Email-confirm'])
{
echo "Your Email was not correctly confirmed, please make sure that you enter the same Email in both fields.<br><br>";
}

else{break}

echo "The information you gave was:<br><br>";

echo "$_POST[First_Name], ";
echo "$_POST[Last_Name]<br>";
echo "$_POST[Age] yrs old<br><br>";
echo "$_POST[Email]<br><br>";
echo "$_POST[Reason]";

}

?>


#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 27 June 2006 - 09:55 AM

Sorted your problems out.
$newLine = "/n";

echo "The infomation you entered is as follows.  If it is incorrect, please re enter the information <a href = 'Emails.php'>here</a><br><br>";


foreach($_POST as $field => $value)
{
    if(empty($_POST[$field]))
    {
        echo "You left the <font color = 'red'>$field</font> field empty.  If you want to submit the request please go back
        and fill in this field,  <br><br>";

        echo "<a href = 'Emails.php'>click here to restart request</a>";
        echo "<br><br>";
    }
}

if($_POST['Email'] != $_POST['Email-confirm'])
{
    echo "Your Email was not correctly confirmed, please make sure that you enter the same Email in both fields.<br><br>";
}
else
{
    echo "The information you gave was:<br><br>";

    echo "$_POST[First_Name], ";
    echo "$_POST[Last_Name]<br>";
    echo "$_POST[Age] yrs old<br><br>";
    echo "$_POST[Email]<br><br>";
    echo "$_POST[Reason]";
}
Your had an extra un-needed closing } braket in your code.

#9 PC Nerd

PC Nerd
  • Members
  • PipPipPip
  • Advanced Member
  • 1,122 posts
  • LocationAustralia

Posted 27 June 2006 - 10:05 AM

sorted your problems out.


thanks, that code was really being annoying


thanks,

#10 Guest_edwinsweep_*

Guest_edwinsweep_*
  • Guests

Posted 27 June 2006 - 10:08 AM

hi pc nerd.
i used to have the same mistake's as you have now.
jedit made it alot easyer for me
its a javascript based editor also suitable for PHP.
jedit also keeps track of al the opening and closing tags in your script.
and it changes color realtime so HTML is a different color than PHP, and mysql is yet another color.
if you dont see the color's working in jedit its because you havent saved the file as a .PHP file yet.
they say zend studio is also a good development platform.
i havent tried it to be honest.
good luck and cya later!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users