Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2011
    Location
    WInchester, Hampshire. UK
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Unexpected elseif PHP result

    I am passing variables from this page:

    http://test.southampton-property.com/index.php

    From the property search section.

    When the variables are passed to:

    http://test.southampton-property.com/listing.php

    I want the property search at the top of the page to highlight your previous selections.

    I have used the following code in the form to populate the selection:

    Code:
    <label>
    <select name="st">
    <?php if ($st="ALL")
    {echo "<option value=\"ALL\" selected=\"selected\">All</option>";}
    elseif ($st="BUNG")
    {echo "<option value=\"BUNG\" selected=\"selected\">Bungalow</option>";}
    elseif ($st="COTT")
    {echo "<option value=\"COTT\" selected=\"selected\">Cottage</option>";}
    elseif ($st="FLAT")
    {echo "<option value=\"FLAT\" selected=\"selected\">Flat</option>";}
    elseif ($st="HOUS")
    {echo "<option value=\"HOUS\" selected=\"selected\">House</option>";}
    elseif ($st="STUD")
    {echo "<option value=\"STUD\" selected=\"selected\">Studio</option>";}
    ?>
    <option value="ALL">All</option>
    <option value="BUNG">Bungalow</option>
    <option value="COTT">Cottage</option>
    <option value="FLAT" <?php if ($st="")
    {echo "<option value=\"FLAT\" selected=\"selected\">Flat</option>";}
    else {echo ">Flat</option>";} ?></option>
    <option value="HOUS">House</option>
    <option value="STUD">Studio</option>
    </select>
    </label>
    No matter what the value of st is the if command always echoes the "ALL" option. I have checked the value by echoing the value of st.

    The second PHP if command in the FLAT option is in case the person comes direct to the page and the string is empty.

    This is driving me mad – any help would be really appreciated!

    :-)

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    A little php 101 here..

    = is an assignment operator. That means you use it to assign a value to a variable which is what you are doing above.

    You want the == operator which COMPARES.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    sblatch (05-02-2013)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    you are declaring a variable '=' instead of comparing '==' , should be

    PHP Code:
    if ($st=="ALL"
    you will need to update all of them to the comparison operator

    Edit: beaten too it by tango

  • Users who have thanked itxtme for this post:

    sblatch (05-02-2013)


  •  

    Tags for this Thread

    Posting Permissions

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