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 to the CF scene
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Post PHP - If else within if else

    What did I do wrong here?

    I'm kind of new to PHP coding...

    Thanks in advance, guys!

    PHP Code:
    <?php
    chdir
    ('/home/csufhous/public_html/example.com/forums');
    define("IN_MYBB"1);
    require 
    './global.php';

    if(
    $mybb->user['uid']){
    if((
    $mybb->user['postnum']) >= 30){
    echo 
    'Registration is currently closed.';
    }
    else{
    echo 
    'You have not met the requirements.';
    }
    else{
    echo 
    "<form action='forums/member.php' method='post'>
    Username: <input type='text' name='username' size='25' maxlength='30' /><br />
    Password: <input type='password' name='password' size='25' />
    <input type='hidden' name='action' value='do_login'>
    <input type='hidden' name='url' value='index.php' />
    <input type='submit' class='submit' name='submit' value='Login' /></form><br>"
    ;
    }
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You can enable error reporting to show of any particular issues with:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    You have a syntax error about half way through. Your logic flow is doesn't properly terminate the first if statement. Immediately after this:
    PHP Code:
    else{
    echo 
    'You have not met the requirements.';

    Simply add a }. If you were to indent your code at each level, you would see this:
    PHP Code:
    if($mybb->user['uid']){
        if((
    $mybb->user['postnum']) >= 30){
            echo 
    'Registration is currently closed.';
        }
        else{
            echo 
    'You have not met the requirements.';
        }
        else{
            echo 
    "<form action='forums/member.php' method='post'>
            Username: <input type='text' name='username' size='25' maxlength='30' /><br />
            Password: <input type='password' name='password' size='25' />
            <input type='hidden' name='action' value='do_login'>
            <input type='hidden' name='url' value='index.php' />
            <input type='submit' class='submit' name='submit' value='Login' /></form><br>"
    ;
        } 
    Is what you have logically, so that would attempt to apply to ELSE clauses to a single IF.

    Avoid using chdir just to perform inclusions (or any explicit full paths inside of anything except potentially a globally included file). Use relative paths; this way if you change your host or webserver than you don't need to update all of your code again. I can't tell you what goes into the relative block, but if you describe where this file is in relation to chdir location than I could tell you what it needs to be.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    budprime (01-18-2013)

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Fou! I really appreciate your help.

    //I posted another thread. It's the same script with the fixes you mentioned, but I added onto it.


  •  

    Posting Permissions

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