Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1

    Default mysql_fetch_array(): not a valid result?

    Error:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\wamp\www\randomn\index.php on line 32

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\wamp\www\randomn\index.php on line 33
    index.php
    PHP Code:
    <?php

    session_start
    ();
    include(
    "config.php");

    if (
    $_GET['login'])
    {
        switch (
    $_GET['login'])
        {
            case 
    '1':
            
            echo(
    "Welcome to something not worth the warm welcome.
                 
                 <form action='?login=2' method='post'>
                 <strong>Username</strong>: <input type='text' name='username' size='20' />
                 <br /><br />
                 <strong>Password</strong>: <input type='text' name='password' size='20' />"
    );
            
            break;
            
            case 
    '2':
            
            
    $username $_POST['username'];
            
    $password $_POST['password'];
            
    $password md5($password);
                
            if (
    $username == "" || $password == "")
            {
                die(
    "You did not enter a username and/or password.");
            }
            
            list(
    $user) = mysql_fetch_array(mysql_query("SELECT `username` FROM `staff` WHERE username='$username'"));
            list(
    $pass) = mysql_fetch_array(mysql_query("SELECT `password` FROM `staff` WHERE password='$password'"));
                
            if (
    $username == "$user&& $password == "$pass")
            {
                
    $sql mysql_query("SELECT * FROM `staff` WHERE username='$user' AND password='$pass'");
            
                if (
    mysql_num_rows($sql) != 1)
                {
                    die(
    "Error...");
                }
                    
                
    $result mysql_fetch_array($sql);
                    
                
    $_SESSION['user'] = $result['username'];
                
    $_SESSION['level'] = $result['level'];
                
    $_SESSION['ip'] = $_SERVER['REMOT_ADDR'];
                
                
    header("location: home.php");
                    
                }
            
            break;
        }
    }
    else if (!
    $_GET['login'])
    {
        
    header("location: ?login=1");
    }
    else
    {
        die(
    "Error.");
    }

    ?>
    config.php (table is commented out because I've already added it)
    PHP Code:
    <?php

    $host 
    "localhost";
    $user "root";
    $pass "";
    $data "hab";

    $connect mysql_connect($host$user$pass);

    if (!
    $connect)
    {
        echo(
    "Error connecting to database.");
    }

    mysql_select_db($data);

    /*
        mysql_query("CREATE TABLE `users` (
                                       `id` int(255) NOT NULL auto_increment,
                                       `username` varchar(500) collate latin1_general_ci NOT NULL,
                                       `password` varchar(500) collate latin1_general_ci NOT NULL,
                                       `level` varchar(500) collate latin1_general_ci NOT NULL,
                                       PRIMARY KEY  (`id`)
                                       ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=44 ;
                                        ") or exit("Couldn't create users table.");
                                        
        echo("Users table created."); */
        
    ?>
    Any ideas why its giving me this error? I'm testing on localhost, wampserver.

  2. #2

    Default

    Fixed, was an error in the mysql table.

  3. #3
    Join Date
    Nov 2008
    Posts
    75
    Tokens
    0

    Default

    Next time if you want to figure out what happened, use mysql_error();

    mysql_query("blabla") or die(mysql_error());

Posting Permissions

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