Jump to content

ManiacDan

Staff Alumni
  • Posts

    2,604
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by ManiacDan

  1. Quotes are required around strings in mysql:

     

    mysql_query ("INSERT INTO `reports`(`user`, `reportedplayer`, `by`, `reason`) VALUES ('$myusername', '$reportedplayer', '$by', '$reason')");

    You can't just stick an echo after mysql_query() and expect that to tell you if the query succeeded. You need to actually handle the error:

    $result = mysql_query ("INSERT INTO `reports`(`user`, `reportedplayer`, `by`, `reason`) VALUES ('$myusername', '$reportedplayer', '$by', '$reason')");
    if ( $result === false ) {
     echo "MySQL Error Encountered: " . mysql_error();
    }

    Edit: Also, if you're using GET for this form, stop. Use POST. You should never send usernames and passwords over GET, they show up in the URL. You also must run these values through mysql_real_escape_string(). Move your mysql_connect up to the top of the script, and then:

     

    $myusername = mysql_real_escape_string($_POST['user']);

     

  2. Commas at the ends of the array declaration are valid, oddly enough.

     

    There are two places in PHP where errant commas are valid:

    1) Trailing commas in array declarations:

    $a = array( 1,2,3, );

     

    2) Initial commas within list():

    list(,$a) = explode(",", $Foo);

  3. Just FYI. Fields used in the ON clause of a JOIN matter as well. Since those are usually FOREIGN KEYS, they are usually indexed anyway; but it bears mentioning here.

    Very true as a general note, his queries didn't use joins so I didn't mention it. Foreign keys are sometimes indexed, but new users especially rarely know they even exist.
  4. $sth2=mysql_query($query2);
    
    $Location=$sth2['fullname'];

    If "not working' means "PHP throws a serious warning about this line being wrong," then you're not calling the appropriate fetch function on your result.

     

    If "not working" means "no errors, I just don't know what's happening," turn errors on, then see sentence #1.

  5. Jo and Ja are not initials, they're some portion of the first name.

     

    You have to do heavy processing of this on the PHP end to turn it into something like:

    WHERE (firstname LIKE 'Jo%' OR lastname LIKE 'Jo%') AND (firstname LIKE 'Doe%' OR lastname LIKE 'Doe%');

     

    Even then, you may get false positives since there's no way to tell which order the names are in.

  6. Please use [ code ] or [ php ] tags so we can actually see your code properly.

     

    There's nothing I could see in login.php that would automatically do a redirect. Are you sure you're hitting that page? How are you being redirected? Do you have firebug or anything installed so you can confirm the header() calls are working?

     

    You should call die(); after every header redirect.

  7. I can't believe there's not a custom-unique function...weird.

     

    This is a handshake problem. A quick and dirty solution to it is:

    foreach ( $array as $key => $val ) {
     foreach ( $array as $key2 => $val2 ) {
       if ( $key == $key2 ) continue;
       if ( $val['b'] == $val2['b'] && $val['c'] == $val2['c'] ) {
         //the current pair is a duplicate according to your criteria
       }
     }
    }

    Note that this is inefficient, for loops would be better, but this is easier to understand.

  8. Just to be clear: This method works perfectly well for every non-reserved character. Characters like @, #, &, ?, /, and = are reserved for use as URL delimiters, which is why they need to be escaped. All you'd have to do is change #hello to $hello (or something else) and it would have started working. Unless you're relying on the specific behavior of jump-to-tag while also trying to get that tag in a PHP script, in which case you should know that jumping to tags on the same page never refreshes the page, so PHP never happens.

  9. If the string is UTF-8, the string is UTF-8. All characters in the string are UTF-8 encoded. Strings aren't like MP3s, they're not variable bitrate.

     

    If, like requinix said, you want to find the first character in the string which has a multi-byte encoding, then that's a whole other question and you could conceivably do it in regex with a unicode range. Look up how to do unicode characters in regex (something like \u123), then put a range [a-z] in your code where A is the first character you want to detect and Z is the maximum possible value.

     

    Or just use string functions.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.