Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-14-2005, 11:12 PM   PM User | #1
doyle_loader
New Coder

 
Join Date: May 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
doyle_loader is an unknown quantity at this point
Whitespace on login

Hey Everyone!

I'm working at a simple authentication section with only 3 login names and 3 encrpyted passwords. I can always get that to work fine, but I tried something new and now I'm getting a white screen.

Code:
<?php
session_register("User");

if (!isset($_SESSION['User']))
	{
	// User not logged in, redirect to login page
	Header("Location: main.html");
	}
	
//Connect to database
$conn = mysql_connect("blah","blah","blah");

if (!$conn) {
   echo "Unable to connect to DB: " . mysql_error();
   exit;
}

if (!mysql_select_db("bda")) {
   echo "Unable to select BDA: " . mysql_error();
   exit;
}

		
if ($User == Student) {
$sql2 = "SELECT Link, Title, Description, Permissions
		From Members
		Where Permissions = '$User'
		Order by Title Asc";
		
		$result = mysql_query($sql2);
}

if ($User == Teacher) {
$sql2 = "SELECT Link, Title, Description, Permissions
		From Members
		Where Permissions = '$User'
		Order by Title Asc";
		
		$result = mysql_query($sql2);
}

else ($User == Administration) {
$sql2 = "SELECT Link, Title, Description, Permissions
		From Members
		Where Permissions = '$User'
		Order by Title Asc";
		
		$result = mysql_query($sql2);
}

?>

<html>

<head>

<title>Members Section</title>

<link href="CssFiles/body_frame.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
function autofitIframe(id){ // v.1.0
//copyright 2004 Eddie Traversa http://www.dhtmlnirvana.com/
if (!window.opera && !document.mimeType && document.all && document.getElementById){
parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
}
else if(document.getElementById) {
parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
}
}
</script>

</head>

<body onload="autofitIframe('contentFRM');">
<h3><i>Welcome to the <? [Permissions] ?>'s Section</i></h3>

<?

echo "<table border=0 padding=0>";

echo "<tr><th>Your Options:</th><th>Description:</th></tr>";

/*Define Colours*/
$color1 = "white";
$color2 = "#EFEFEF";
$row_count = 0; 

while ($row = mysql_fetch_assoc($result)) {

/* PHP alternate colors between the two colors defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2; 

   // Add 1 to the row count

    $row_count++; 

   echo "<tr><td bgcolor='$row_color' BORDER=0 CELLPADDING=0 CELLSPACING=0>";

?>

   <a target="_blank" href="
   <?php 
   echo $row['Link'];
   ?>">
   <?php
   echo $row['Title'];
   ?>
   </a>
   
   <?php
   echo $row['Description'];
   echo "</td></tr>";
   
}
   echo "</table>";
  
mysql_free_result($result);
   ?>

<!--Log out link here!-->
<p><a href=\"logout.php\">Logout!</a></p>
</body>
</html>
What I wanted to happen was to be able to display different links on this members page for users to do stuff such as post news for users A, and B but only user B can Post News and change passwords. I figured if I used an IF statement this may work, but no dice for me . The javascript section I have there is just to expand an IFRAME's height and works fine so that shouldn't be causing the problem.

Any help would be great! Thanks!

Chris

Last edited by doyle_loader; 06-15-2005 at 02:05 AM..
doyle_loader is offline   Reply With Quote
Old 06-15-2005, 01:17 AM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Don't post your info for your mysql_connect()!!
Where is $User defined? and make sure to use quotes when comparing your values
if ($User == "Student")
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 06-15-2005, 02:09 AM   PM User | #3
doyle_loader
New Coder

 
Join Date: May 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
doyle_loader is an unknown quantity at this point
Thanks! I did even notice the mysqlconnect!

$User comes from the login form before. I'm pretty sure it passes correctly because it worked fine it another script I did.

I will try the quotes however, have get back!

Cheers,

Chris
doyle_loader is offline   Reply With Quote
Old 06-15-2005, 02:55 AM   PM User | #4
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Just remember register globals is off by defualt nowadays, therefore you should use $_POST and $_GET
So it would be $_POST['User'] if you run into any troubles post back.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 06-15-2005, 01:43 PM   PM User | #5
doyle_loader
New Coder

 
Join Date: May 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
doyle_loader is an unknown quantity at this point
Hey! I have the script working now. I used Brandos idea and put quotes around Student, Teacher, and Administration as well as replaced the else statement. Another slight change was within the <h3> tags where I changed the php statement. Thanks to Brando for the help!

I am however getting a strange error on the page with line 14. It isn't affecting the script, so i'm not worried there, but it is kind of weird because it says that the error is with my:
echo "Unable to connect to DB: " . mysql_error();

Weird! If someone thinks they know what's wrong and wish to enlighten me go right ahead.

Here is my slightly modified script:

Code:
<?php
session_register("User");

if (!isset($_SESSION['User']))
	{
	// User not logged in, redirect to login page
	Header("Location: admin.html");
	}
	
//Connect to database
$conn = mysql_connect("host","name","passwd");

if (!$conn) {
   echo "Unable to connect to DB: " . mysql_error();
   exit;
}

if (!mysql_select_db("DB")) {
   echo "Unable to select BDA: " . mysql_error();
   exit;
}

if ($User == "Student") {
$sql2 = "SELECT Link, Title, Description, Permissions
		From Members
		Where Permissions = '$User'
		Order by Title Asc";
		
		$result = mysql_query($sql2);
	}


if ($User == "Teacher") {
$sql2 = "SELECT Link, Title, Description, Permissions
		From Members
		Where Permissions = '$User'
		Order by Title Asc";
		
		$result = mysql_query($sql2);
	}

if ($User == "Administration") {
$sql2 = "SELECT Link, Title, Description, Permissions
		From Members
		Where Permissions = '$User'
		Order by Title Asc";
		
		$result = mysql_query($sql2);
	}



?>

<html>

<head>

<title>Members Section</title>

<link href="CssFiles/body_frame.css" rel="stylesheet" type="text/css" />


<script type="text/javascript">
function autofitIframe(id){ // v.1.0
//copyright 2004 Eddie Traversa http://www.dhtmlnirvana.com/
if (!window.opera && !document.mimeType && document.all && document.getElementById){
parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
}
else if(document.getElementById) {
parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px"
}
}
</script>

</head>

<body onload="autofitIframe('contentFRM');">		

<h3><i>Welcome to the <?=$User?>'s Section</i></h3>

<?
echo "<table border=0 padding=0 width='450'";

echo "<tr><th>Your Options:</th><th>Description:</th></tr>";

/*Define Colours*/
$color1 = "white";
$color2 = "#EFEFEF";
$row_count = 0; 

while ($row = mysql_fetch_assoc($result)) {

/* PHP alternate colors between the two colors defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2; 

   // Add 1 to the row count

    $row_count++; 

   echo "<tr bgcolor='$row_color'><td BORDER=0 CELLPADDING=5 CELLSPACING=5 width='25%'>";

?>

   <a target="_blank" href="
   <?php 
   echo $row['Link'];
   ?>">
   <?php
   echo $row['Title'];
   ?>
   </a>
   </td><td width='75%'>
   <?php
   echo $row['Description'];
   echo "</td></tr>";
   
}
   echo "</table>";
  
mysql_free_result($result);
   ?>

<!--Log out link here!-->
<p><a href=logout.php>Logout!</a></p>

</body>
</html>
Cheers


Chris
doyle_loader is offline   Reply With Quote
Old 06-15-2005, 03:25 PM   PM User | #6
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
What's the error you're getting?
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-15-2005, 04:14 PM   PM User | #7
doyle_loader
New Coder

 
Join Date: May 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
doyle_loader is an unknown quantity at this point
Hey

It's in IE's status bar

Line: 14
Char:1
Error: Unspecified Error
Code: 0
Url: http://www.k12.nf.ca/hcch/members.php
doyle_loader is offline   Reply With Quote
Old 06-15-2005, 05:13 PM   PM User | #8
delinear
Regular Coder

 
Join Date: Feb 2005
Location: West Midlands, UK
Posts: 623
Thanks: 0
Thanked 0 Times in 0 Posts
delinear is an unknown quantity at this point
If the error is in the status bar then it's almost certainly a javascript error. As far as I know there is no way PHP would ever display an error in the status bar.

If you view source on the page you'll see that line 14 of the source is:

PHP Code:
if (!window.opera && !document.mimeType && document.all && document.getElementById){ 
I'd recommend asking the javascript guys to take a look at it
__________________
~ Bazzy
delinear is offline   Reply With Quote
Old 06-15-2005, 05:20 PM   PM User | #9
doyle_loader
New Coder

 
Join Date: May 2005
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
doyle_loader is an unknown quantity at this point
I just posted in the Javascript forum actually. I'm getting another problem where the expanding IFRAME script i have there doesn't expand. It was working fine but I hope that someone in the Javascript forum will answer my question!

CHeers,

Chris
doyle_loader is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:24 AM.


Advertisement
Log in to turn off these ads.