+ Reply to Thread
Results 1 to 4 of 4

Thread: another php/sql question!

  1. #1
    matzomeal is offline x10Hosting Member matzomeal is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    4

    another php/sql question!

    <?php
    $host = "localhost";
    $dbusername = "*********";
    $dbpassword = "*********";
    $dbname = "matzo_friendbase";
    $tblname = "users";

    mysql_connect($host, $dbusername, $dbpassword) OR die("Cannot connect.");
    mysql_select_db($dbname) OR die("Cannot select database.");

    $username = $_POST['uname'];
    $pass = $_POST['pword'];

    echo "username: " . $username;
    echo "password: " . $pass;

    $sql = "SELECT * FROM $tblname WHERE name=$username AND password=$pass";
    $result = mysql_query($sql) OR die("Problem running query.");

    $count = mysql_num_rows($result);
    if($count==1) {
    session_register("myusername");
    session_register("mypassword");
    } else {
    echo "Wrong username or password.";
    }
    ?>


    keeps telling me "Problem running query", and I'm not sure what's exactly wrong with the query. I have a table named 'users' with 4 columns: 'name' 'password' 'email' and 'user_id'. Any suggestions?

    EDIT: i fixed it. i needed single quotes around the $username and $pass in the sql statement
    Last edited by matzomeal; 05-26-2009 at 05:47 PM. Reason: fixed

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

    Re: another php/sql question!

    You also need to sanitize your input.

    Is users.name unique?
    Last edited by misson; 05-26-2009 at 06:08 PM.

  3. #3
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: another php/sql question!

    FYI, matzomeal, there is a nice little feature to include PHP/HTML/regular code into a website. You simply wrap the php code with [ PHP ] [ /PHP ].
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  4. #4
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    Re: another php/sql question!

    Quote Originally Posted by xav0989 View Post
    FYI, matzomeal, there is a nice little feature to include PHP/HTML/regular code into a website. You simply wrap the php code with [ PHP ] [ /PHP ].
    Just a little technicality. You mean forum and the tags are called BBcode.

+ Reply to Thread

Similar Threads

  1. Inactivity Suspension Question
    By DeanKennedy in forum Free Hosting
    Replies: 1
    Last Post: 07-07-2008, 09:07 AM
  2. Swauv - Question Time!
    By SEŅOR in forum Off Topic
    Replies: 7
    Last Post: 03-22-2008, 01:38 PM
  3. Lottery Website (kind of)
    By admintwo in forum Earning Money
    Replies: 4
    Last Post: 12-29-2007, 05:07 PM
  4. Odd question but will I be banned for this?
    By sielk in forum Free Hosting
    Replies: 3
    Last Post: 09-28-2007, 11:29 AM
  5. SQL Question
    By DizzyTechnology in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 01-16-2007, 07:56 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