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 6 of 6

Thread: Mysql help

  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mysql help

    Hello, I am in need of some help.
    PHP Code:
    $id mysql_real_escape_string($_GET['username']);
    $hwid mysql_real_escape_string($_GET['hwid']);
     
    $query "SELECT * FROM `user` WHERE `username` ='{$id}'";

    $result mysql_query($query);

    echo 
    "<table border='1'>
    <tr>
    <th>Group</th>
    <th>Hwid</th>
    </tr>"
    ;
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<tr>";
      echo 
    "<td>" $row['usergroupid'] . "</td>";
      echo 
    "<td>" $row['hwid'] . "</td>";
      echo 
    "</tr>";
      }
    echo 
    "</table>";


    if(
    $result['hwid'] == "" or !isset($result['hwid'])) {
    mysql_query("UPDATE user SET hwid='{$hwid}' WHERE `username` ='{$id}'");
    }

    mysql_close();
    ?> 
    I am trying to make it where the hwid will only change if it is blank.
    the problem is this line "if($result['hwid'] == "" or !isset($result['hwid'])) {"
    Will be skipped and it will get straight to the one under it.
    The row will change even it is not blank.
    I only want it so that the row will only change once if it is only blank or empty.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,516
    Thanks
    77
    Thanked 4,379 Times in 4,344 Posts
    $result["anything"] is meaningless.

    You have to use $row["hwid"] to find out if it is there or not.

    But WHY are you using a while loop if you only expect to get, at most, one user???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I updated it to
    PHP Code:
    if($row['hwid'] == "" or !isset($row['hwid'])){
    mysql_query("UPDATE `user` SET hwid='{$hwid}' WHERE `username` ='{$id}'");

    but it is still changing the row for the user even if the row is not blank.

    Look at this: http://dystopia-x.com/GetHW.php?username=test&hwid=1234
    It will set the hwid to 1234, but once you put a 5 in it and input that into the yrl it will change 1234 to 1235 even tho is only post to change if the field is blank/empty.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,516
    Thanks
    77
    Thanked 4,379 Times in 4,344 Posts
    SO DEBUG DEBUG DEBUG.

    Code:
    $currenthwid = $row["hwid"];
    echo "<hr/>DEBUG: current hwid is ::" . $currenthwid . "::<hr/>";
    
    if( ! isset( $currenthwid ) || $currenthwid == "" )
    {
        mysql_query("UPDATE `user` SET hwid='{$hwid}' WHERE `username` ='{$id}'"); 
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't bring back anything.
    Only this:
    DEBUG: current hwid is ::::

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,516
    Thanks
    77
    Thanked 4,379 Times in 4,344 Posts
    Well, I don't use PHP, so I don't know why that if condition would then continue on to do the update.

    But you could always do this:
    Code:
        $sql = "UPDATE user SET hwid='" . $hwid . "' WHERE username = '" $id . 
    "' AND IFNULL(hwid,'') <> '' ";
        mysql_query( $sql );
    And then you don't even need to mess with the if test.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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