Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Help with an If statement

  1. #1
    Join Date
    Mar 2010
    Posts
    40

    Default Help with an If statement

    Hi Newbie here. I have a form that is rating satisfaction with companies that you do business with. To try to eliminate duplicate entries because of spelling errors, I've populated a drop down with already rated companies (name is company_2). If the company you want to rate is in the dropdown you "choose" it and go on. If it is not in the dropdown box, then there is another "box" (name is company) to enter that company.

    My database has one field for "company".

    I'm thinking that somewhere I need an if statement that looks at the "company" box and if there is a name in there then use it, if its blank, then use the "chosen" "company_2" in the dropdown box and change it to "company" to add it to the database..

    If company field is empty then $company =company_2 else $company=$_POST['company'];

    I'm hoping one of you wizards understands what I need and can help me get there.

    Thanks.
    Last edited by pitzerwm; 03-May-2010 at 04:21 AM.

  2. #2
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: Help with an If statement

    derive_fields is wot u want:

    http://www.tectite.com/fmhowto/derived.php

    say, company is the field u want to end up with
    company_2 is the drop down selection
    and other_company is the manual text entry field.

    this should do it:
    HTML Code:
    <input type="hidden" name="derive_fields"
     value="company=%if(company_2;company_2;other_company)%" />
    that assumes ur company_2 field has an empty value if the user wants to manually enter other_company, like this:
    HTML Code:
    <select name="company_2">
    <option value="">Not in the list below</option>
    <option value="IBM">IBM</option>
    <option value="Apple">Apple</option>
    <option value="Intel">Intel</option>
    </select>

  3. #3
    Join Date
    Mar 2010
    Posts
    40

    Default Re: Help with an If statement

    Thanks craptree, I've tried your solution and I must be doing something wrong:

    Code:
    <input type="hidden" name="derive_fields"  value="imgverify=recaptcha_response_field,realname=FirstName + LastName,company=%if(company_2;company_2;other_company)% "/>
    added the blank line to the dropdown:

    Code:
    <select name="country2" size="5">
    <option value="">Not in List, use box below</option>
              <option value="A-OK Equipment Co">A-OK Equipment Co</option>
    Other box

    Code:
    <input name="other_company" type="text" size="30" maxlength="25" />
    the results are that the field is blank in the database whether you use the list or type in the box.

    Thanks for your help.
    Last edited by pitzerwm; 03-May-2010 at 08:14 PM.

  4. #4
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: Help with an If statement

    so, no error?

    did it write to the db when u previously entered company? in other words, how do u know the db stuff is working?

  5. #5
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: Help with an If statement

    also, do u get an email with the right value in the company field?

  6. #6
    Join Date
    Mar 2010
    Posts
    40

    Default Re: Help with an If statement

    no there is no error message. I can look at the database, and all is entered correctly except the company. Before I added the drop down box the entry worked fine and even when I put in the drop down box I could pick one or the other but since I called both "boxes" the same name it ignored the first one. That is when I changed the name, and was looking at an if statement.

    It also sends me the email, and if I use the drop down box it still calls it company_2: if I use the other_company box, the mail says other_company:

  7. #7
    Join Date
    Mar 2004
    Posts
    2,224

    Default Re: Help with an If statement

    sounds like the company field is not being created

    wot's the URL of ur form so I can check wot u did?

    btw, company_2 and other_company don't just disappear....if u don't want them in the email, u can use mail_options Exclude

  8. #8
    Join Date
    Mar 2010
    Posts
    40

    Default Re: Help with an If statement

    no there is no error message. I can look at the database, and all is entered correctly except the company. Before I added the drop down box the entry worked fine and even when I put in the drop down box I could pick one or the other but since I called both "boxes" the same name it ignored the first one. That is when I changed the name, and was looking at an if statement.

    It also sends me the email, and if I use the drop down box it still calls it company_2: if I use the other_company box, the mail says other_company:

    I think that I have a typo in the derive_fields as I have 2 other items in it

  9. #9
    Join Date
    Mar 2010
    Posts
    40

    Default Re: Help with an If statement

    the URL is http://www.autocareforum.com/ratings/rating_entry.php

    You will note that the actual name of the field is "distr" rather than "company" as I was trying to make it clearer in this forum.

    Thanks again for your time.

  10. #10
    Join Date
    Mar 2010
    Posts
    40

    Default Re: Help with an If statement

    This is from the email, using the type in box

    who: 1
    other_distr: new company 2
    distr_head: WA
    Product: Supplies/Chemicals
    model: supplies
    This is using the dropdown box

    who: 1
    distr_2: A-OK Equipment Co
    other_distr:
    distr_head: WA
    Product: Maintenance

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 29-Oct-2008, 12:45 PM
  2. Replies: 0
    Last Post: 20-Feb-2008, 06:52 PM
  3. Replies: 4
    Last Post: 05-Jul-2007, 04:07 AM
  4. Replies: 2
    Last Post: 05-Jul-2007, 02:41 AM

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
  •