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 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if statement not working

    I have been struggeling with this problem all morning and I really can't figure it out. I have used this many times in the past, it's very simple but not working this time.

    I have a simple form to search a database:

    Code:
    <form method="post" action="result-list.php">
    <input name="search-party" type="hidden" value="y">
    <div style="padding:4px; border-style:solid; border-width:1px; border-color:#ccc; background-color:#fff">
    <b>Find Parties:</b>&nbsp;
    <input type="text" size="8" name="q">
    <input type="submit" value="go!">
    <br />
    <div align="right">
    <a href="submit-party1.php">List your party</a>
    </div>
    </div>
    </form>
    In the processing file, I check for the presence of the search-party, then include a chunk of code to search the DB:

    Code:
    if ($search-parties == "y")
    {
    include("result-parties.php");
    }
    Strangely, the if statement is ignored, whether or not $search-parties is passed and regardless of its value.

    If I print $search-parties, it shows "0".

    Any idea?

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try

    Code:
    if ($_POST['search-parties'] == "y")
    {
    include('result-parties.php');
    }

  • #3
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    In your form, you're using the variable name search-party, but your PHP references it as $search-parties.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks that works!

  • #5
    New Coder
    Join Date
    Jun 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you shouldn't use variable with the - sign, otherwise php can understand it like a math example


  •  

    Posting Permissions

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