CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   PHP - If else within if else (http://www.codingforums.com/showthread.php?t=286009)

budprime 01-18-2013 02:31 PM

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>"
;
}
?>


Fou-Lu 01-18-2013 02:42 PM

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.

budprime 01-18-2013 03:13 PM

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.


All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.