Click to See Complete Forum and Search --> : Whitepage on login! Booo


doyle_loader
06-14-2005, 02:11 PM
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 :rolleyes:. 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

doyle_loader
06-15-2005, 07:46 AM
Hey! I have the script working now. A poster from another forum gave me the idea to put quotes around Student, Teacher, and Administration. I also replaced the else statement as well as made a slight change within the <h3> tags.

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