Jump to content

inserting


ryanmetzler3

Recommended Posts

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?

Link to comment
Share on other sites

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 by requinix
Link to comment
Share on other sites

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 by ryanmetzler3
Link to comment
Share on other sites

 


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; 
 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.