Web Hosting Forums

Results 1 to 4 of 4

This is a discussion on else if statements not working in the Hosting Talk & Chit-chat forum
sorry guys another problem here basic problem but i can't figure it out why won't this code work <form action="admin.php?action=docheck"> <input type="radio" name="page" value="none">none<br> <input ...

  1. #1
    Loyal Client
    Join Date
    Feb 2002
    Posts
    90

    else if statements not working

    sorry guys another problem here

    basic problem but i can't figure it out

    why won't this code work

    <form action="admin.php?action=docheck">
    <input type="radio" name="page" value="none">none<br>
    <input type="radio" name="page" value="staff">staff page<br>
    <input type="radio" name="page" value="news">news page<br>
    <input type="submit" value="Post News"><br>
    </form>
    <font color="#000000">


    <?
    if ($action == "docheck") {

    if ($page="staff page") echo "Staff Selected";
    elseif ($page=="news page") echo "News Selected";
    elseif ($page=="none") echo "Selected Nothing";

    elseif (!$page) echo "Neither Selected";

    }
    ?>

    http://216.118.121.28/admin.php
    admin/admin

  2. #2
    Chairman Still Shady's Avatar
    Join Date
    Sep 2001
    Location
    Redmond, WA-nnabe
    Posts
    1,184
    else if must be 2 words...

    if ($expression) {

    }
    else if {

    }
    else {

    }
    Where do you wanna go today?

  3. #3
    Loyal Client
    Join Date
    Mar 2002
    Posts
    34
    Originally posted by Still Shady
    else if must be 2 words...

    if ($expression) {

    }
    else if {

    }
    else {

    }
    Nope, http://www.php.net/manual/en/control...res.elseif.php. Both "elseif" and "else if" are acceptable.

    if ($page="staff page") echo "Staff Selected";

    This condition will always return true, I think you mean:

    if ($page == "staff") echo "Staff Selected";

    Also, I believe:

    elseif ($page=="news page") echo "News Selected";

    Should be:

    elseif ($page=="news") echo "News Selected";

    so we get:

    Code:
    <?php
    if ($action == "docheck")
    { 
        if ($page="staff")
            echo "Staff Selected";
        elseif ($page=="news")
            echo "News Selected";
        elseif ($page=="none")
            echo "Selected Nothing";
        elseif (!$page)
            echo "Neither Selected";
    }
    ?>
    If that doesn't work, instead of that last elseif(!$page), try elseif(!isset($page))

    HTH
    steven

  4. #4
    Loyal Client
    Join Date
    Feb 2002
    Posts
    90
    cool and thanks

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
  •