Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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")

  • #3
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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.

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What's the error you're getting?

  • #7
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #9
    New Coder
    Join Date
    May 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •