PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
a94060
Forum Regular
Posts: 543 Joined: Fri Feb 10, 2006 4:53 pm
Post
by a94060 » Wed May 31, 2006 4:53 pm
Hi, I have this script here and im not sure why i am getting this error:
My script is :
Code: Select all
<?PHP
session_start();
//simple check to see if the person is logged in
if($_SESSION['in'] != TRUE) {
echo 'You are not logged in,please log in at the admin area.';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Page</title>
<style type="text/css">
<!--
.style1 {font-size: 16px}
.style4 {font-size: 24px}
-->
</style>
</head>
<body>
<h1>
<?PHP
else {
?>
</h1>
<div align="center" class="style1">
<p class="style4"> Admin Login</p>
<form id="form1" name="form1" method="post" action="login.php">
<p>Username
<input name="you" type="text" id="you" />
</p>
<p>Password
<input name="me" type="text" id="me" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Submit2" value="Reset" />
</p>
</form>
<p> </p>
<div align="center" class="style1"></div>
</div>
<?PHP
}
?>
</body>
</html>
can anyone tell me what i have done wrong (voided any of the if else statement rules?)
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed May 31, 2006 5:34 pm
Ignoring all that HTML, your code is:
Maybe separating your code and HTML might help you.
(#10850)
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed May 31, 2006 6:14 pm
Do this...
Code: Select all
<?php
session_start();
//simple check to see if the person is logged in
if($_SESSION['in'] != TRUE) {
echo 'You are not logged in,please log in at the admin area.';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Page</title>
<style type="text/css">
<!--
.style1 {font-size: 16px}
.style4 {font-size: 24px}
-->
</style>
</head>
<body>
<h1>
<?php
} else {
?>
</h1>
<div align="center" class="style1">
<p class="style4"> Admin Login</p>
<form id="form1" name="form1" method="post" action="login.php">
<p>Username
<input name="you" type="text" id="you" />
</p>
<p>Password
<input name="me" type="text" id="me" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Submit2" value="Reset" />
</p>
</form>
<p> </p>
<div align="center" class="style1"></div>
</div>
<?php
}
?>
</body>
</html>
a94060
Forum Regular
Posts: 543 Joined: Fri Feb 10, 2006 4:53 pm
Post
by a94060 » Wed May 31, 2006 6:42 pm
so i guess it was probably a problem with my brackets?
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed May 31, 2006 6:55 pm
a94060 wrote: so i guess it was probably a problem with my brackets?
Maybe this makes it clearer:
Code: Select all
if () {
} YOU HAVE TEXT HERE else {
}
Again, maybe separating your code and HTML might help you.
(#10850)
a94060
Forum Regular
Posts: 543 Joined: Fri Feb 10, 2006 4:53 pm
Post
by a94060 » Wed May 31, 2006 7:21 pm
so,i had code outside of the brackets? I still dont seem to udnerstand (only 14) can u just tell me.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed May 31, 2006 7:38 pm
Yep ... with the
control structures you need to put code between the { and } (or only have one code line).
(#10850)
a94060
Forum Regular
Posts: 543 Joined: Fri Feb 10, 2006 4:53 pm
Post
by a94060 » Wed May 31, 2006 7:58 pm
sorry... i did not seem to understand that i had garbage that was outside of the brackets. My fault