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