Results 1 to 5 of 5

Thread: Help with integrated PHP

  1. #1
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default Help with integrated PHP

    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:

    Code:
    <?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.

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    there is a semi-colon after the elseif meaning elseif(condition) blank and then you have brackets that belong to nothing
    Code:
    <?php
    
    $string = $_GET['email'];
    
    if ($string == "invalid")
    	{
    ?>
    The email you entered was invalid.
    <?php
    }
    
    elseif ($string == "empty");
    	{
    ?>
    You need to enter an email.
    <?php
    	}
    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. The Following User Says Thank You to Master_script_maker For This Useful Post:

    Schmoopy (01-10-2009)

  4. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ah how silly of me, thanks very much

  5. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    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 Code:
    <?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,".")))
    Last edited by bluewalrus; 01-10-2009 at 02:54 PM. Reason: added some more things

  6. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •