Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2013, 02:31 PM   PM User | #1
budprime
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
budprime is an unknown quantity at this point
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>"
;
}
?>
budprime is offline   Reply With Quote
Old 01-18-2013, 02:42 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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'); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
budprime (01-18-2013)
Old 01-18-2013, 03:13 PM   PM User | #3
budprime
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
budprime is an unknown quantity at this point
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.
budprime is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:46 PM.


Advertisement
Log in to turn off these ads.