If-else..plz help

Discussion in 'PHP' started by Hades, Dec 18, 2008.

  1. #1
    Man, I swear I am going to figure out how these work one day, but for now, can anyone help me out. I need the following to work:

    <?php if ( $user_ID ) 
    			<ul>
    				<li>
    					<strong>You are logged in</strong>
    				</li>
    			</ul>
    		else()
    		<ul>
    			<li>
    				 <form action="<?php bloginfo('url') ?>/wp-login.php" method="post">
    				<div>
    				<label for="log">Username: <input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22" /></label><br />
    				<label for="pwd">Password: <input type="password" name="pwd" id="pwd" size="22" /></label><br />
    				<input type="image" id="loginsubmit" src="images/login.jpg" alt="login" />
    				<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
    				</div>
    			</form>
    			</li>	
    			
    </ul> ?>
    PHP:
     
    Hades, Dec 18, 2008 IP
  2. ayaw

    ayaw Peon

    Messages:
    164
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you accidentally removed the "{ ?>" at top and "<?php }" at bottom.
     
    ayaw, Dec 18, 2008 IP
    talismanclick likes this.
  3. Yesideez

    Yesideez Peon

    Messages:
    196
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Format:
    if (condition) {
      code
    } else {
      code
    }
    Code (markup):

    <?php if (condition) { ?>
      HTML
    <?php } else { ?>
      HTML
    } ?>
    Code (markup):
     
    Yesideez, Dec 18, 2008 IP
    starrychloe likes this.
  4. fireworking

    fireworking Peon

    Messages:
    460
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes. The { ?>" at top and "<?php } is very important. Dont worry, when I was new, I made that mistake too.

    Also, you could just safe from closing the php tags by using echo 'all your long text here i/'m doing fine';

    Just remember to escape which is annoying.
     
    fireworking, Dec 18, 2008 IP