...

View Full Version : Whitespace on login



doyle_loader
06-15-2005, 12:12 AM
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.



<?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

Brandoe85
06-15-2005, 02:17 AM
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")

doyle_loader
06-15-2005, 03:09 AM
Thanks! I did even notice the mysqlconnect! :eek:

$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

Brandoe85
06-15-2005, 03:55 AM
Just remember register globals is off by defualt nowadays, therefore you should use $_POST and $_GET (http://www.php.net/manual/en/language.variables.external.php)
So it would be $_POST['User'] if you run into any troubles post back.

doyle_loader
06-15-2005, 02:43 PM
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:



<?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

delinear
06-15-2005, 04:25 PM
What's the error you're getting?

doyle_loader
06-15-2005, 05:14 PM
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

delinear
06-15-2005, 06:13 PM
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:


if (!window.opera && !document.mimeType && document.all && document.getElementById){

I'd recommend asking the javascript guys to take a look at it :)

doyle_loader
06-15-2005, 06:20 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum