Click to See Complete Forum and Search --> : simple if loop not working!!!!


dudhi
10-17-2007, 11:14 AM
this is my loop
<?php
SESSION_START();

IF ( SESSION['LOGGED'] == 1 )
{
?>
<a href = "blah blah blah > blah blah </a>
<? php
}

The problem is, that if loop is not working or at least it doesn't show the link. May be I am doing something wrong.

scragar
10-17-2007, 11:55 AM
$_session?

dudhi
10-17-2007, 12:25 PM
if ( ( $_SESSION["logged"]) == 1)
{
<a href = " blah blah blah " > blah blah </a>

scragar
10-17-2007, 12:31 PM
try echoing it out, maybe it's not been set.

Declan1991
10-17-2007, 12:35 PM
Also it's <?php not <? php. I think that it must be the former. if is lowercase too.

dudhi
10-17-2007, 12:48 PM
k, if I try doing this
if ( ( $_SESSION["logged"]) == 1)
{
include("XXX.php");
}

this loop works fine but if I put in
<a href = blah blah blah > blah blah </a> instead of include ("xxx.php") that doesn't work. :(

scragar
10-17-2007, 01:03 PM
if($_SESSION["logged"]) == 1){
echo '<a href="blah">blah</a>';
}

dudhi
10-17-2007, 01:12 PM
Tried this but didn't work.
echo '<a href="xxx.php"> Manage Account </a>';

on the web page it shows "Manage Account '; ?>" but not as a link.......

scragar
10-17-2007, 01:14 PM
can you give me a link? it looks like the source isn't being processed by PHP...

NightShift58
10-17-2007, 01:30 PM
on the web page it shows "Manage Account '; ?>" but not as a link.......You need to have "<?php" somewhere before the echo statement.
<?php
session_start();
if ($_SESSION["logged"]) == 1) {
echo '<a href="blah">blah</a>';
}
?>

MrCoder
10-17-2007, 01:33 PM
You need to have "<?php" somewhere before the echo statement.
<?php
session_start();
if ($_SESSION["logged"]) == 1) {
echo '<a href="blah">blah</a>';
}
?>

Or the other way round, you have a closing "?>" somewhere by mistake.

scragar
10-17-2007, 01:35 PM
it wouldn't produce the text displayed with either of those problems.

as I said, it's obvious that, for some reason, the page isn't treating the PHP code as php, it's treating it as HTML.

NightShift58
10-17-2007, 01:39 PM
it's obvious that, for some reason, the page isn't treating the PHP code as php, it's treating it as HTML.Yes, the missing <?php will do that.

In his previous examples, the include() worked. At some later point, he must have tested without the <?php.

scragar
10-17-2007, 01:41 PM
but then it would have writen out the
session_start();
and such lines as well. the link would also have appeared instead of just the text.

NightShift58
10-17-2007, 01:42 PM
Or the other way round, you have a closing "?>" somewhere by mistake.
I think more would be displayed, including the <a href>.

NightShift58
10-17-2007, 01:44 PM
but then it would have ...I think he just copied and pasted something in a script to do a quick test.

He'll tell us in a bit, I'm sure.

scragar
10-17-2007, 01:44 PM
it would have appeared in the source, but from the starting php tag to the > in the a href would have been seen as one large invalid tag, hence why the browser wouldn't show it.

dudhi
10-17-2007, 01:46 PM
K, Its on my localhost server so don't have a link to the file but I am copying the whole file to you.


<?php
ob_start(); // overheads all of your output to the browser being buffered in //the server until you send it
SESSION_START();


/* if its logged in then includes the primary.php that shows a link to manage the account*/
if ( ( $_SESSION["loggedin"]) == 1)
{
include("primary.php");
}
else
{
echo '<a href="http://localhost/triton/newtriton.php"> Manage Account </a>';
?>
<html>

<head>
<script src="http://localhost/triton/one.js" type= "text/javascript" >
</script>
<link rel="stylesheet" type="text/css" href="login.css" />
</head>


<div class = "page" >

<body >
<a href = "http://localhost/triton/first.php"> <img class = "home" src="http://localhost/triton/home.jpg" > </a>
<a href = "http://localhost/triton/login.php"> <img class = "login" src="http://localhost/triton/login.jpg" > </a>


<div id = "top">

<img class = "maveriklogo" src="http://localhost/triton/maverick_logo.jpg" > <br>
</div>


<div class = "toplinks">
<table>

<tr> <td > <img class = "location" src="http://localhost/triton/locations.jpg"> </td>
<td > <img class = "card" src="http://localhost/triton/cards.jpg"> </td>
</tr>
</table>
</div>

<div class = "toplinksright">
<table >

<tr> <td > <img class = "location" src="http://localhost/triton/Specials.jpg"> </td>
<td > <img class = "card" src="http://localhost/triton/about.jpg"> </td>
</tr>
</table>
</div>




<div class = "left">



Like I said if u replace the include("primary.php") with
<a href="http://localhost/triton/newtriton.php"> Manage Account </a>

thats the whole reason I have to include "primary.php". In primary.php its just adding one more link to it.

scragar
10-17-2007, 01:52 PM
no closing brace to the else...

NightShift58
10-17-2007, 01:56 PM
You win, dudhi...

You need to turn on error reporting on your local host. It would have told you quite a few things... and saved you almost 3 hours...

dudhi
10-17-2007, 03:29 PM
<?php
ob_start(); // overheads all of your output to the browser being buffered in the server until you send it
SESSION_START();


/* if its not logged in then asks the user to enter the username and password again. */
if ( ( $_SESSION["loggedin"]) == 1)
{
include("primary.php");
}
else
{
echo '<a href="http://localhost/triton/newtriton.php"> Manage Account </a>';
?>
<html>

<head>
<script src="http://localhost/triton/one.js" type= "text/javascript" >
</script>
<link rel="stylesheet" type="text/css" href="login.css" />
</head>


<div class = "page" >

<body >
<a href = "http://localhost/triton/first.php"> <img class = "home" src="http://localhost/triton/home.jpg" > </a>
<a href = "http://localhost/triton/login.php"> <img class = "login" src="http://localhost/triton/login.jpg" > </a>


<div id = "top">

<img class = "maveriklogo" src="http://localhost/triton/maverick_logo.jpg" > <br>
</div>


<div class = "toplinks">
<table>

<tr> <td > <img class = "location" src="http://localhost/triton/locations.jpg"> </td>
<td > <img class = "card" src="http://localhost/triton/cards.jpg"> </td>
</tr>
</table>
</div>

<div class = "toplinksright">
<table >

<tr> <td > <img class = "location" src="http://localhost/triton/Specials.jpg"> </td>
<td > <img class = "card" src="http://localhost/triton/about.jpg"> </td>
</tr>
</table>
</div>




<div class = "left">

Have u had ur adventure today ?
<img class = "monster" src="http://localhost/triton/monster.jpg">
<a href= "http://www.maverikmonster.com" target= _blank class = "monsterbanner" > www.maverikmonster.com </a>
</div>

<div class = "mainparagraph">

</div>

</body>


<div class="bottom">
<a href = "" onclick= "contact()" > Contact us </a>. <a href = "" onclick = "contact()" > Privacy policy </a> . <a href = ""> Terms & Conditions. </a>
</div>

</div>


</html>
<?php } ?>




hopefully this time it won't cut when I post something. I haven't changed anything since the last post. its the original code. Sorry about not posting the whole code, but there is no error. Trust me.

MrCoder
10-17-2007, 05:15 PM
echo '<a href="http://localhost/triton/newtriton.php"> Manage Account </a>';


That line is displayed before the <HTML> tag, surely that must cause some issues?


<div class = "page" >

<body >

..................

</body>


<div class="bottom">
<a href = "" onclick= "contact()" > Contact us </a>. <a href = "" onclick = "contact()" > Privacy policy </a> . <a href = ""> Terms & Conditions. </a>
</div>

</div>


You also have multiply <DIV> tags outside of the <BODY> tag.

dudhi
10-18-2007, 12:36 AM
Mr. Coder
I think before it was caching my page, but it seems to be working fine now.
All I have to do was echo ' <a href = " " > blah blah </a>';
Now when I tried moving it before html or that ending the </div> I can't replicate this problem. so I am assuming it problem with cache earlier and just didn't load my page right. But thanks for your help, it was simple enough but been crazy over this for two days. :D