PDA

View Full Version : Help with integrated PHP



Schmoopy
01-10-2009, 02:32 PM
Hi there, I'm a complete novice to this, and may be a little bit out of my depth, but the problem I'm having seems pretty basic.

Basically, I have the following code which is part of a big page with lots of other HTML on it, so it jumps in and out of PHP:



<?php

$string = $_GET['email'];

if ($string == "invalid")
{
?>
The email you entered was invalid.
<?php
}

elseif ($string == "empty");
{
?>
You need to enter an email.
<?php
}
?>


When the user enters their email it gets sent to "subscribers.php" which performs some checks and then sends back the corresponding URL depending on the error.

That part works fine, but if the php sends back the "The email you entered was invalid", it executes the other if statement as well, but I don't know why, since it's an elseif. I did try "return false" at the end of it too but then stopped the rest of the page from running.

Any suggestions?

Thanks,

Jack

P.S - Can't link to the site where this is at to give you a demo because it's passworded but if you need more information just say what you need.

Master_script_maker
01-10-2009, 02:42 PM
there is a semi-colon after the elseif meaning elseif(condition) blank and then you have brackets that belong to nothing
<?php

$string = $_GET['email'];

if ($string == "invalid")
{
?>
The email you entered was invalid.
<?php
}

elseif ($string == "empty");
{
?>
You need to enter an email.
<?php
}
?>

Schmoopy
01-10-2009, 02:48 PM
Ah how silly of me, thanks very much :)

bluewalrus
01-10-2009, 02:51 PM
Also you don't need to end all of those php's you can do it all in one with echo, you can also put html tags in the echo. like...


<?php

$string = $_GET['email'];

if ($string == "invalid")
{
echo "The email you entered was invalid.";
}

elseif ($string == "empty");
{
echo "You need to enter an email.";
}
?>

Also are you trying to find if those things happen or is this just an example? If your trying to find it try these out (not as written but i think you'll get it).

if(empty($email)
and
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))

Schmoopy
01-10-2009, 05:13 PM
Ah yea, forgot about those echos, but for validating the email I just took a function off another site that checks for proper email formatting.