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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: Stupid Errors

  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    94
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Stupid Errors

    Every single time I try to login it gives me that echo "Sorry"
    login_success.php
    PHP Code:
    <?php  require("config.php"); require_once("include/menu.php"); ?>
    <div id="container">
    <div id="content">
    <script type="text/javascript">
    <!--
    function delayer(){
        window.location = "../javascriptredirect.php"
    }
    //-->
    </script>
    </head>
    <body onLoad="setTimeout('delayer()', 3000)">
    <h2 >&nbsp;</h2>
    <p>&nbsp;</p> 
    <div align="center">
      <?php

    if ($level =="1" ) { echo "You are now being logged in, as a User"; }
     else {
    if (
    $level =="2" ) { echo "You are now being logged in, as a Moderator"; }
     else {
    if (
    $level =="3" ) { echo "You are now being logged in, as a Super Moderator"; }
     else {
    if (
    $level =="4" ) { echo "You are now being logged in, as an Administrator"; }
     else { echo 
    "Sorry"; }}}}

    ?>
    config.php

    PHP Code:
    <?php session_start();
    mysql_connect("localhost","root") or die(mysql_error());
    mysql_select_db("maindb") or die(mysql_error()); 


    $result mysql_query("SELECT level FROM members WHERE username='$username'");
    $row mysql_fetch_assoc($result); // The results are stored in an sql result array -we need to extract them
    $level $row['level']; // Since we extracted it into an array, get the correct index of the array
    if ($level == "0" ) {

    }else { 
    if (
    $level == "2" ) {


    }else { 
    if (
    $level == "3" ) {


    }else { 

    if (
    $level == "4" ) {


    }else { 

    }
    }
    }
    ?>
    I want the login_success.php page to work. I just posted config.php because maybe it has to do with that. PLEASE help me.

  • #2
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    Try echo'ing the variables in different places to make sure they're set correctly (like when they're pulled from the database)

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    94
    Thanks
    11
    Thanked 0 Times in 0 Posts
    It still doesn't work.

  • #4
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    What happens with this?
    Code:
    <?php session_start();
    mysql_connect("localhost","root") or die(mysql_error());
    mysql_select_db("maindb") or die(mysql_error()); 
    
    
    $result = mysql_query("SELECT level FROM members WHERE username='$username'");
    $row = mysql_fetch_array($result); // The results are stored in an sql result array -we need to extract them
    print_r($row);
    $level = $row['level']; // Since we extracted it into an array, get the correct index of the array
    if ($level == "0" ) {
    
    }else { 
    if ($level == "2" ) {
    
    
    }else { 
    if ($level == "3" ) {
    
    
    }else { 
    
    if ($level == "4" ) {
    
    
    }else { 
    
    }
    }
    }
    } ?>
    Last edited by malfist; 06-13-2008 at 08:09 PM.

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    94
    Thanks
    11
    Thanked 0 Times in 0 Posts
    That doesn't work either.

  • #6
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    What does the print_r say?

  • #7
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    This is dangerous:
    Code:
    $result = mysql_query("SELECT level FROM members WHERE username='$username'");
    What happens if the user enters SQL instead of a username? Like '; DROP DATABASE;

  • #8
    New Coder
    Join Date
    May 2008
    Posts
    94
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Still don't work.

  • #9
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    What does the print_r echo?
    print_r doesn't do anything except echo variables, such as arrays.

  • #10
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Same as before: you're not assigning a value to $username before you use it.

  • #11
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by tomws View Post
    Same as before: you're not assigning a value to $username before you use it.
    Unless he's got it set so that $username is the same as $_POST['username'].

    What does echo $username show?

  • #12
    Regular Coder
    Join Date
    Apr 2007
    Posts
    295
    Thanks
    0
    Thanked 19 Times in 19 Posts
    Didn't we have this problem in another thread already?

    @NightFlyer Echo. Your. Variables.

    Seriously, we can't walk you through every single step of debugging a script, you're gonna have to learn how to do some of it on your own, these past 5 or so threads for example, you keep having very similar problems that you might not otherwise

  • #13
    New Coder
    Join Date
    May 2008
    Posts
    94
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Internet Explorer

    I have got it to work as I forgot my variable $username. Thank you guys.

  • #14
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by mr e View Post
    Didn't we have this problem in another thread already?
    You can teach the technique of debugging, but you can teach the desire to debug.

  • #15
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by tomws View Post
    You can teach the technique of debugging, but you can teach the desire to debug.
    Leave off, everybody makes mistakes. Especially people new to things. If he's not familiar with OOP debugging he's not going to do it. It's not his fault, he just needs to learn. Insulting him isn't a way to produce debugging results, just the same as telling a teenager they can't do something because they'll do it anyway.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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