/    Sign up×
Community /Pin to ProfileBookmark

help with Sessions and Password thing

ok i have this code

[code=php]
<?php
include(“header.php”);
$passw=”seltzer”;
if($passw==$password)
{
$_SESSION[‘loggedin’]==”1″;
}
elseif($_SESSION[‘loggedin’]==”1″)
{
$un = “”;
$pass = “”;
$db = “”;
$host = “localhost”;

$sql = mysql_connect($host, $un, $pass) or die(mysql_error());
mysql_select_db($db, $sql) or die(mysql_error());
$query = “SELECT * FROM school ORDER BY `ID` DESC LIMIT 5″;// this makes sure that the newest news is first
$results = mysql_query($query) or die(mysql_error());

echo'<div class=”content”>’;

echo'<div class=”top”>Hw Entries</div>’;
while ($row = mysql_fetch_row($results))
{
echo'<h3>’.$row[1].'</h3><br><p>’.nl2br($row[2]).'</p><br>Added on &nbsp;’.$row[3].’&nbsp;|<a class=”menu” href=”entry.php?ID=’.$row[0].’ “>Add/View Comment(s)</a><hr>’;
}
}

else
{
echo”<div class=’content’><div class=’top’>Enter Pass</div><form action=’index.php’ method=’POST’>Enter Password:<input type=’password’ name=’password’><input type=’submit’ name=’submit’></div>”;
}

include(“footer.php”);
?>
[/code]

I have this code but it doesnt work.

When i go to the page first it displayts the else statement but once hit submit it just displays a blank page. Shouldnt it display my content because $password is equal to $pass

O yeah and the else statement displays until i gett the pass correct.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ConorauthorApr 28.2004 — i also tried this with the same result

[code=php]
<?php
include("header.php");
$passw="seltzer";



if($_SESSION['loggedin']=="1")
{
$un = "";
$pass = "";
$db = "";
$host = "localhost";

$sql = mysql_connect($host, $un, $pass) or die(mysql_error());
mysql_select_db($db, $sql) or die(mysql_error());
$query = "SELECT * FROM school ORDER BY ID DESC LIMIT 5";// this makes sure that the newest news is first
$results = mysql_query($query) or die(mysql_error());

echo'<div class="content">';

echo'<div class="top">Hw Entries</div>';
while ($row = mysql_fetch_row($results))
{
echo'<h3>'.$row[1].'</h3><br><p>'.nl2br($row[2]).'</p><br>Added on &nbsp;'.$row[3].'&nbsp;|<a class="menu" href="entry.php?ID='.$row[0].' ">Add/View Comment(s)</a><hr>';
}
}


else
{
if($submit=="")
{
echo"<div class='content'><div class='top'>Enter Pass</div><form action='index.php' method='POST'>Enter Password:<input type='password' name='password'><input type='submit' name='submit'>";
if($password==$passw)
{
$_SESSION['loggedin']="1";
echo"Correct Password</div>";
}
}
}


include("footer.php");
?>[/code]
×

Success!

Help @Conor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...