+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP problem - if / else

  1. #1
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    PHP problem - if / else

    currently the code in question looks like this:

    HTML Code:
        <tr>
          <td width="140" height="30" align="left" valign="top">Interests</td>
          <td width="320" height="30" align="left" valign="top"><input type="checkbox" name="exhibitions" value="yes" <?php if ($exhibitions == 'yes') ?> checked="checked" /><?php } else { ?> /> <?php } ?>
            Exhibitions</td>
        </tr> 
    There's a series of check boxes on a form for updating subscription preferences. What I'd like them to do is show up as 'checked' if someone has previously opted in, or not if they haven't.

    I've tried a few methods, but nothing is working so far.

    Any pointers as to where this is going wrong?

    The current error message is "Parse error: syntax error, unexpected T_ELSE in /home/stevetur/public_html/testarea/cms/about/subscribe_update.php on line 132"

    thanks

  2. #2
    ichwar's Avatar
    ichwar is offline Community Advocate ichwar is an unknown quantity at this point
    Join Date
    Dec 2008
    Location
    NC, USA
    Posts
    1,454

    Re: PHP problem - if / else

    <tr>
    <td width="140" height="30" align="left" valign="top">Interests</td>
    <td width="320" height="30" align="left" valign="top"><input type="checkbox" name="exhibitions" value="yes" <?php if ($exhibitions == 'yes') ?> checked="checked" /><?php } else { ?> /> <?php } ?>
    Exhibitions</td>
    </tr>

    You start an if declaration there, but you never you never tell it what to do.:nuts:

  3. #3
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: PHP problem - if / else

    You are missing an opening bracket { after the if():

    Code:
    <?php if ($exhibitions == 'yes') {?> checked="checked" />

  4. #4
    stevet70 is offline x10Hosting Member stevet70 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    35

    Re: PHP problem - if / else

    thanks gomarc, works perfectly now

  5. #5
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: PHP problem - if / else

    I would like to add another comment, primarily for efficiency. Since the /> is repeated twice, you can remove it from the if clause:
    PHP Code:
    <?php if ($exhibitions == 'yes') { ?> checked="checked" <?php ?>/>
    Last edited by xav0989; 05-21-2009 at 04:23 PM.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  2. problem in php mail function and smtp
    By idrees in forum Free Hosting
    Replies: 2
    Last Post: 02-08-2008, 05:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  5. php ad code problem
    By sourabhj in forum Free Hosting
    Replies: 7
    Last Post: 08-22-2006, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers