Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Dec 2004
    Posts
    67
    Member #
    8452
    Liked
    1 times
    I can't give you anything, but I really need to know what's wrong NOW.

    PHP Code:
    mysql_connect($host,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");

    $query "SELECT credits FROM krypto WHERE user = '" $user "' AND pass = '" $pass "'";
    $result mysql_query($query);


    if (!
    $result) {
       echo 
    'Could not run query: ' mysql_error();
       exit;
    }
    echo 
    mysql_result($result3);

    mysql_free_result($result);

    mysql_close(); 
    It just outputs nothing.
    Brian : This must be the physics department.
    Chris : That explains all the gravity.

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,672
    Member #
    1234
    Liked
    142 times
    Right after
    PHP Code:
    $result mysql_query($query); 
    do
    PHP Code:
    echo "result = "$result ."\n"
    see what is outputted. Also, right before
    PHP Code:
    $result mysql_query($query); 
    do
    PHP Code:
    echo "query = "$query ."\n"
    that may help in the t/s process.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Member
    Join Date
    Dec 2004
    Posts
    67
    Member #
    8452
    Liked
    1 times
    Hmm...
    Code:
    query = SELECT credits FROM krypto WHERE user=admin AND pass=xxxxxxxx result = Could not run query: Unknown column 'admin' in 'where clause'
    That is with the query changed to:
    PHP Code:
    SELECT credits FROM krypto WHERE user=$user AND pass=$pass 
    Brian : This must be the physics department.
    Chris : That explains all the gravity.

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    You don't need to concatenate variables in queries like you do above, you can write the variables directly within the double quotes defining the $sql variable. (only when dealing with array values, do you have to separate the extracted value from the confines of double quotes)

    i.e., your query can look like:
    $query = " SELECT credits FROM krypto WHERE user = '$user' AND pass = '$pass' ";
    --------
    If the user 'admin' exists, make sure to place the username 'admin' within singlequotes in your query! (not like your printed query indicates above)
    ----------

    Whenever I run any sort of PHP script using/producing SQL queries, I always echo/print the queries to screen first, to check that all variables/arrays/case-switch-statements/if-else-statements are handled appropriately.
    When the output loks good (tested through a variety of possible inputs on the form side of the application, where certain radiobuttons have been marked, certain user-variables are uniqely identified, choices are made, etc, etc)

    I test all the different query outputs (through copy/paste) in a GUI MySQL application (phpMyAdmin, MySQLCC, Navicat, or what have you)
    Then you can immediately see if your queries are valid, or missing some syntactical logic, that are not always apperant when making complex sub-selects or join-queries.

    When you figre out what error in your SQL that makes the query fail, you adjust your code accordingly.
    Only on a very few occations have I been able to generate a query that works on first attempt.
    S. Rosland


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com