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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post PHP MySQL "Resource ID #4" Problem

    Hi, I'm making a website and it requires a user area. I've gotten code to make a login script, but when a user logs in they get the error:

    Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1

    This is the code for the manage-check.php file, which the index page sends the user information to:
    PHP Code:
    <?php
    session_start
    ();
    include(
    'db.php');

    if(isset(
    $_POST['submit'])) :
        
    // Username and password sent from signup form
        // First we remove all HTML-tags and PHP-tags, then we create a sha1-hash
        
    $username strip_tags($_POST['username']);
        
    $password sha1(strip_tags($_POST['password']));

        
    // Make the query a wee-bit safer
        
    $query mysql_query("SELECT ID FROM system_users WHERE username = '%s' AND password = '%s' LIMIT 1;");
        
    $result mysql_query ($query
              or die(
    "Query error: "mysql_error());
            
            
    // Register the user ID for further use
            
    $_SESSION['member_id'] = $row['id'];
            
    header('Location: members-only.php');
    endif;
    phpinfo();
    ?>
    The database file code is this:
    PHP Code:
    <?php
    define
    ('SQL_USER''root');
    define('SQL_PASS''-');
    define('SQL_DB',   'vet_database');

    // Creates link to the database server
    $link mysql_connect('localhost'SQL_USERSQL_PASS);
    if(!
    $link) :
        die(
    'Could not connect: ' mysql_error());
    endif;

    // Select a database where our member tables are stored
    $db mysql_select_db(SQL_DB$link);
    if(!
    $db) :
        die (
    'Can\'t connect to database : ' mysql_error());
    endif;
    ?>
    The MySQL database table that stores the information is set out in the following way with the current information:

    id username password status emp_no first_name last_name member_id
    1 wolfetone cat 1 1 David Richards
    1


    The PHP version is 5, and the MySQL version is 5.0.45. Any help would be apprieicated. By the way, I'm not that proficient in PHP so excuse me for the amateurish mistakes in the code lol.

  • #2
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Sounds like it's not getting a result... try printing your query and running that through your mysql program... and try putting 'id' in small letters, not caps.

    You also need to fetch it to an array before looking for the rows...
    PHP Code:
    $row mysql_fetch_array($result); 
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #3
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by wolfetone View Post
    Code:
    	// Make the query a wee-bit safer
    	$query = mysql_query("SELECT ID FROM system_users WHERE username = '&#37;s' AND password = '%s' LIMIT 1;");
    
    ?>
    thats actually gotta be

    PHP Code:
    $query mysql_query(
      
    sprintf("SELECT ID FROM system_users WHERE username = '%s' AND password = '%s' LIMIT 1;"$username$password)
    ); 
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    There are actually two queries. The first one should not be a query at all, but should be changed to sprintf.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I put in the suggestions given, it now brings up the following:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\manage-check.php on line 34.

    Although, after this it displays the phpinfo result.

  • #6
    New Coder
    Join Date
    Jan 2008
    Location
    Portugal
    Posts
    17
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Hi,

    Have you tried to print the query and run it in your mysql? ie. phpMyAdmin?

    That can be for many reasons, though I believe it's a field mispell, but it can be a crashed table also, for example...

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    The original code you posted had error checking and error reporting on the mysql_query(). This would have told you why the query failed. You need to add the following onto the mysql_query() statement -

    PHP Code:
    or die("Query error: "mysql_error()); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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