ryanmetzler3 Posted September 18, 2013 Share Posted September 18, 2013 if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; I want to display an advertisement that is saved to a php file called "littlead.php". If the "if" portion of the statement above is run only then I want to display the ad in a certain location, which requites a <div>. If the "else" is executed then I want to display it in a different location. So I basically I need to do this code: <div> include 'littlead.php'; </div> in both the if and else statement. But I cant because the include function is not recognized by HTML. And the html is not recognized by PHP. Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/ Share on other sites More sharing options...
requinix Posted September 18, 2013 Share Posted September 18, 2013 New to PHP? <div> <?php include 'littlead.php'; ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/#findComment-1449969 Share on other sites More sharing options...
ryanmetzler3 Posted September 18, 2013 Author Share Posted September 18, 2013 New to PHP? <div> <?php include 'littlead.php'; ?> </div> That does not work. You can't put <div> tags inside php code. The <div> tags have to be inside the if/else statement. Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/#findComment-1449971 Share on other sites More sharing options...
requinix Posted September 18, 2013 Share Posted September 18, 2013 (edited) So yes, you are. <div> <?php include 'littlead.php'; ?> </div> <?php if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; }Or if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; } ?> <div> <?php include 'littlead.php'; ?> </div> Edited September 18, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/#findComment-1449973 Share on other sites More sharing options...
ryanmetzler3 Posted September 18, 2013 Author Share Posted September 18, 2013 (edited) So yes, you are. <div> <?php include 'littlead.php'; ?> </div> <?php if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; }Or if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; } else { $form = "<div id='forms'> <form action='login.php' method='post'> <table class='forms'> <td>Username:</td> <td><input type='text'name='user'/></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password'/></td> </tr> <td></td> <td><input type='submit' name='loginbtn' value='Login'/></td> </tr> <tr> <td><a href='register.php'>Register</a></td> <td><a href='forgotpass.php'>Forgot Password?</a></td> </tr> </table> </form> </div>"; } ?> <div> <?php include 'littlead.php'; ?> </div> That is not what I am trying to accomplish. I get that you are saying, but I want the <div> inside the php if statement. The way you have it set up the ad will display all the time no matter what. The if statement detects if the user is already logged in. If the user is logged in I want it to display an ad below their username. If they are not logged in, I just want it to display the log in form and no ad. So the include 'littlead.php'; needs to be in the if statement. But I can not put <div> tags around that because it is inside PHP tags. Ideally this is what I want but it does not work: if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; <div>include 'littlead.php';</div> //this is what does not work, but I want it only to show the ad if the if statement is run , and not the else statement so it needs to be here. } else { blah blah blah; Edited September 18, 2013 by ryanmetzler3 Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/#findComment-1449974 Share on other sites More sharing options...
vinny42 Posted September 18, 2013 Share Posted September 18, 2013 but it does not work: Of course, you are ignoring what is being said and just randmonly trying things out that you probably already know doesn't work. Try this: if ($username && $userid) { echo "You are already logged in as <b>$username</b>"; echo "<br/>Not " . $username . "? <a href='logout.php'>Logout</a>"; echo "<div>"; include 'littlead.php'; echo "</div>"; } else { blah blah blah; Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/#findComment-1450015 Share on other sites More sharing options...
requinix Posted September 18, 2013 Share Posted September 18, 2013 You also said you wanted it in both the if and the else. if { output stuff } else { output stuff } equivalent to output if { stuff } else { stuff } if { stuff output } else { stuff output } equivalent to if { stuff } else { stuff } outputI picked one as an example. Quote Link to comment https://forums.phpfreaks.com/topic/282233-inserting/#findComment-1450018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.