+ Reply to Thread
Results 1 to 10 of 10

Thread: some php sql help needed

  1. #1
    daktarie is offline x10Hosting Member daktarie is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    13

    Question some php sql help needed

    php Mysql for dummies and google got me going but now im stuck

    the database is oke but i made a error in the query some where it needs to control if user and password combination exists
    im puzzeling for 2 day's now and dont get it to run right.
    when it runs it go's direct tho the ELSE statement
    and display's the wrong blblblaaaaaa text
    so my gues is i have the query wrong but cant figure out what.
    any help would be great

    PHP Code:

    <title>Untitled Document</title>
    </head>

    <body>
    <?php

    // data base access
    include('xxxx');
     


    mysql_connect($host$username$password)or die(mysql_error());
    mysql_select_db($database)or die(mysql_error());

    $db_name="daktarie_GPRO";
    $tbl_name="registered_members";

    $name=$_POST['username'];
    $password=$_POST['password'];

    $sql 'SELECT * FROM `registered_members` WHERE name=\'".$name."\' and password=\'".$password."\'""';
    $result=mysql_query($sql);

    if(
    $count==1){

    $_SESSION['username'] = $name
    $_SESSION['password'] = $password;
    header("location:login_success.php");
    }

    else {
    echo 
    "<center><font size='5'>Wrong password or username";
    }

    ?> 
    </body>
    </html>

  2. #2
    DJHolliday is offline x10Hosting Member DJHolliday is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    38

    Re: some php sql help needed

    I'm missing a line here.
    Something like:
    '$count = mysql_num_rows($result)'

    Otherwise I don't see any relation between your SQL Statement and your $count variable.
    But maybe I'm missing something else here.
    DJ
    ---------------------------------------------
    Quis Custodiet Ipsos Custodes?

  3. #3
    flinx is offline x10Hosting Member flinx is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    68

    Re: some php sql help needed

    Quote Originally Posted by DJHolliday View Post
    I'm missing a line here.
    Something like:
    '$count = mysql_num_rows($result)'

    Otherwise I don't see any relation between your SQL Statement and your $count variable.
    But maybe I'm missing something else here.
    True.

    And there's something wrong with the query string too. You start the string with a single quote, and close it with a double quote when you want to add the $name and $password. Just use double quotes at the beginning and the end of the whole string. That way PHP will substitute the two variables with their value:

    PHP Code:
    $sql "SELECT * FROM registered_members WHERE name='$name' and password='$password'"
    Another thing: never use user inserted values in your queries without validation:

    PHP Code:
    $name=mysql_real_escape_string($_POST['username']);
    $password=mysql_real_escape_string($_POST['password']); 
    One last thing (though maybe the book will talk about that later on): never save passwords in plaintext. Save them encrypted, for example using the MD5 function.
    In that case, you would have something like this to get the $password:

    PHP Code:
    $password=md5(mysql_real_escape_string($_POST['password'])); 
    Last edited by flinx; 11-09-2007 at 07:51 AM.

  4. #4
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: some php sql help needed

    Quicknote: IF you're gonna md5 it, you don't have to escape it. I have never seen a non-escaped md5 hash.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  5. #5
    daktarie is offline x10Hosting Member daktarie is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    13

    Re: some php sql help needed

    Quote Originally Posted by DJHolliday View Post
    I'm missing a line here.
    Something like:
    '$count = mysql_num_rows($result)'

    Otherwise I don't see any relation between your SQL Statement and your $count variable.
    But maybe I'm missing something else here.
    yup your right i posted on accedent the wrong version
    i edited the sugested parts but still with the same result i hate it that i just canrt find out why

  6. #6
    daktarie is offline x10Hosting Member daktarie is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    13

    Exclamation Re: some php sql help needed

    im getting a bit closer to solving the problem.

    now i get this error

    Parse error: syntax error, unexpected T_VARIABLE in /home/daktarie/public_html/checklogin.php on line 22

    22 is this line $count = mysql_num_rows($result)
    but the error must be above it i gues

    so im missing something but im taping in the blind what it is :dunno:
    plz help this old guy is running out of paracetemol

    PHP Code:
    <?php

    //database acces
    include(xxxxx);
     


    mysql_connect($host$username$password)or die(mysql_error());
    mysql_select_db($database)or die(mysql_error());

    $db_name="daktarie_GPRO";
    $tbl_name="registered_members";

    $name=mysql_real_escape_string($_POST['myname']);
    $password=mysql_real_escape_string($_POST['mypassword']);  

    $sql "SELECT * FROM registered_members WHERE myname='$name' and mypassword='$password'";
    $result=mysql_query($sql);

    if(!
    $result){die(mysql_error()

    $count mysql_num_rows($result)



    if(
    $count==1){

    $SESSION ['myname'] = $name
    $SESSION_ ['mypassword'] = $password;
    header("location:member_page.php");
    }

    else {
    echo 
    "<center><font size='5'>Wrong password or username";
    }

    ?>

  7. #7
    Join Date
    Aug 2007
    Location
    Gangstas Paradise
    Posts
    4,143

    Re: some php sql help needed

    Ok, I could be far from wrong here, but shouldnt it look more like:
    PHP Code:
    <?php 

    ....

    $result=mysql_query($sql); 

    if(!
    $result)
    {
     die(
    mysql_error() );
    }
    else
    {
     
    $count mysql_num_rows($result);
    }

    ...

    ?>
    Last edited by DefecTalisman; 11-14-2007 at 05:50 AM.

    http://dev.x10hosting.com (this has nothing to do with x10hosting)

    ->All us helpful people here at x10hosting would like to reach our next user groups, "Community Paragon". Please click the +rep icon on the left hand side of a post if that post was helpfull.



  8. #8
    Cj555 is offline x10Hosting Member Cj555 is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    6

    Re: some php sql help needed

    it should be

    PHP Code:
    $_SESSION['myname'] = $name;
    $_SESSION['mypassword'] = $password
    as opposed to what youve written with _'s all over the place...
    Edit:
    and
    PHP Code:
    if(!$result){die(mysql_error() 
    is wrong

    should be...
    PHP Code:

    if(!$result)
    die(
    mysql_error()); 
    Last edited by Cj555; 11-14-2007 at 07:00 AM. Reason: Automerged Doublepost

  9. #9
    daktarie is offline x10Hosting Member daktarie is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    13

    Re: some php sql help needed

    thanx guys that error check was the part causing the error got it works now

  10. #10
    mvmusic is offline x10Hosting Member mvmusic is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Colorado
    Posts
    24

    Re: some php sql help needed

    regarding escaping strings: if you are going to use mysql_real_escape_string, do stripslashes() first (unless you have PHPv3). magic_quotes_gpc are enabled for v2 and v3 which could cause frustration later on

+ Reply to Thread

Similar Threads

  1. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  2. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  3. PHP and SQL issues.
    By DarkDragonLord in forum Free Hosting
    Replies: 17
    Last Post: 03-29-2007, 10:05 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 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