+ Reply to Thread
Results 1 to 9 of 9

Thread: query help

  1. #1
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    query help

    is this syntax correct?

    $query = "SELECT off_auth.user_id FROM off_auth, off_users WHERE off_auth.user_id = off_users.user_id AND off_auth.passcode = " . $pass . " AND off_users.user_name = \"" . $user . "\";";
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: query help

    Code:
    $query = 
    "SELECT off_auth.user_id 
    FROM off_auth, off_users 
    WHERE off_auth.user_id = off_users.user_id 
    AND off_auth.passcode = '$pass' 
    AND off_users.user_name = '$user'";
    I like to break up my queries so you can see what you're doing a little better. Whitespace and linebreaks are ignored. Using double quotes means that variables will be parsed, so there's no need to do "string " . $var . " string", just "string $var string". You don't need a semicolon on the end of the query. Also, when you are doing comparisons, any strings need to be quoted: "and x = 'y' " not "and x = y"

    A common mistake people make is to make as many tables as possible. This causes confusion, complicated queries, and referential integrity problems.

    If you have tables like this:
    table 1:
    user ID.....user name
    1...............joe
    2...............bob

    table 2
    user ID.....user phone number
    1..............123-123-1234
    2..............123-123-1235

    If each user only has 1 phone number, it makes no sense to add the complexity of another table.
    Last edited by garrettroyce; 05-18-2009 at 08:25 PM.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: query help

    Thanks,. made it right.

    i've got another one. whats d difference between mysql_numrows() to mysql_num_rows()?
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: query help

    mysql_numrows() doesn't exist :P
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  5. #5
    adamparkzer is offline On Extended Leave adamparkzer is just really nice
    Join Date
    Jun 2008
    Location
    IL, USA
    Posts
    3,745

    Re: query help

    Quote Originally Posted by zyreena View Post
    whats d difference between mysql_numrows() to mysql_num_rows()?
    I'm pretty sure mysql_munrows() is just an alias for mysql_num_rows(), which returns the number of rows in a result.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: query help

    In addition to garrettroyce's advice on syntax and table design, there are two security points that should be addressed. Make sure $pass and $user have been sanitized (so that little Robert'; DROP TABLE off_auth;-- won't cause problems when he registers for your site). off_auth.passcode should store a hash (properly salted) of each user's password so that if someone compromises your server and gets the passcodes, they won't yet be able to sign in with stolen credentials (they will first need to find one of the passwords or a collision by brute force).

  7. #7
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: query help

    Quote Originally Posted by adamparkzer View Post
    I'm pretty sure mysql_munrows() is just an alias for mysql_num_rows(), which returns the number of rows in a result.
    Correct!

    mysql_numrows() is a deprecated alias of
    mysql_num_rows()

    source: http://us2.php.net/manual/en/functio...l-num-rows.php

    So you are better off using mysql_num_rows()

  8. #8
    zyreena is offline x10Hosting Member zyreena is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    57

    Re: query help

    therefore mysql_numrows(); no longer exists and should not be used, ryt?

    and no longer supported in the latest version?
    beginner always starts from the scratch
    www.alliancetutorial.x10hosting.com

  9. #9
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: query help

    They've removed the function from their PHP >= 5 documentation at php.net, so they're just keeping the function alive for the lazy coders out there who can't update their code :P

    Using deprecated functions will actually give an error under certain conditions so I would not use them. In this case, it's just a name change, but it's still a bad practice to get into.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread

Similar Threads

  1. MysQL Query for Master table & child table
    By phpasks in forum Programming Help
    Replies: 8
    Last Post: 08-07-2008, 08:07 AM
  2. A simple PHP query..
    By manuraj.dhanda in forum Programming Help
    Replies: 10
    Last Post: 06-04-2008, 03:43 AM
  3. Replies: 0
    Last Post: 03-18-2008, 12:47 AM
  4. TCP Query port, visor de team speak
    By swoop in forum Soporte
    Replies: 3
    Last Post: 09-03-2007, 01:09 PM
  5. [BEG] How to run a SQL query in phpMyAdmin
    By Brandon in forum Tutorials
    Replies: 0
    Last Post: 04-14-2007, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers