Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32

Thread: Need some direction with this script

  1. #11
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Is this still the warning you get?
    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/userdir/foobar/guid-checker.php on line ...
    mysqli_query() returns a mysqli_result object if the query is successful, but returns boolean FALSE if there was a problem. Since you don't check, you're ending up passing FALSE to mysqli_num_rows(), when it expects the object - hence, your error message.

    PHP Code:
    /* snip */
    $result $mysqli->query($query);

    # right about here, you should be checking if the query was successful or not.

        
    if (mysql_num_rows($result)<1){
    /* snip */ 

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Looks like it's mixing mysqli and mysql. Is that ok?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    Looks like it's mixing mysqli and mysql. Is that ok?
    I did not notice that. Nope, not okay, won't work. itivae, you're missing an i in mysqli_num_rows().

    However, that's not what's causing this particular error. You still need to be checking if your query was successful before trying to use it. I would also suggest not mixing object-oriented (e.g., $mysqli->query()) and procedural (e.g., mysqli_num_rows()) styles - choose one or the other.

  4. #14
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,933
    Thanks
    16
    Thanked 303 Times in 302 Posts
    Blog Entries
    9

    Default

    Quote Originally Posted by traq View Post
    Speaking of editors, you'd do well to choose one with syntax highlighting. It makes a world of difference.

    I changed your posts above to use [PHP] tags instead of simple [CODE] tags - as you can see, the error becomes very obvious.
    PSPad http://www.pspad.com/ and Notepad++ http://notepad-plus-plus.org/ as suggested earlier, both have syntax highlighting
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  5. #15
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Thanks for the suggestions. I use several text editors that all have syntax highlighting. I have made some headway on this code but am running into a problem when I try to INSERT data into the database. I have tried using mysqli_query() but I am not getting the confirmation or the error text. Just a blank screen. I have commented on the point that the code works till. Any suggestions would be much appreciated.

    PHP Code:
    <?php
    require_once('connectvars.php');
     
    $mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_NAME);

        
    /* check connection */
    if ($mysqli->connect_errno) {
        
    printf("Connect failed: %s \n"$mysqli->connect_error);
        exit();
            } 
            
        
    $player_name 'itivae'//$_POST['playername'];    
        
    $player_id '1010103'//$_POST['playerid'];    
        
    $guid '4e72f140c35df55909ce551273c44007'//$_POST['guid'];
        
        /*if(!isset($_POST['playernam']) ||
            !isset($_POST['playerid']) ||
            !isset($_POST['guid']) || {
            died('We are sorry, but there appears to be a problem with the form you submitted.');       
        }*/

         
     
        
    $query "SELECT * FROM player_bans WHERE banned_guid = '$guid'";


     if (
    $result $mysqli->query($query)){
    while (
    $obj $result->fetch_object()) {
            
           
    printf ('<div class="bans">'."%s"$obj->banned_guid);
           
    printf (" appears in the ban list" '</div>');
        }
    //WORKS TILL HERE

     
    else {

        
    $query "INSERT INTO player_data (player_name, player_id, guid) 
        VALUES ('
    $player_name', '$player_id', '$guid')"
            
    $result $mysqli->query($query);
        if ( 
    false===$result ) {
      
    printf("error: %s\n"mysqli_error($mysqli));
    }
    else {
         echo 
    'Player: ' $player_name ' ' $player_id ' ' $guid ' has been added to the whitelist.';
        }
       
    }
    $mysqli->close();

    ?>
    Last edited by itivae; 03-15-2013 at 12:01 AM.

  6. #16
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by itivae View Post
    ... but I am not getting the confirmation or the error text. Just a blank screen.
    That is almost always an indication that there was an error, and that your server is configured to prevent display of the error message.

    This is fairly common with web hosting companies. You need to adjust your error reporting settings in your php.ini file, find your server's error log, and/or talk to your web host about how to do so.

  7. #17
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Specifically, it is a parse error-- nothing is displayed because there is a problem understanding the code, so nothing is displayed. (Runtime errors, those found when trying to execute the script, are less severe and will show you at least some content-- a parse error stops the script from executing at all.)

    Most frequently parse errors come from a missing ; or ) or }, but there can be other reasons too.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #18
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Specifically, it is a parse error-- nothing is displayed because there is a problem understanding the code, so nothing is displayed. (Runtime errors, those found when trying to execute the script, are less severe and will show you at least some content-- a parse error stops the script from executing at all.)

    Most frequently parse errors come from a missing ; or ) or }, but there can be other reasons too.
    But other parse errors where returned as a message....does that mean that some do and some dont? I have spoken with my host and it looks like error_reporting is fully enabled..... I am still getting a blank screen..... Any other thoughts?

  9. #19
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Are you certain they were parse errors, not runtime errors? The error messages look very similar, but the first word will be different.

    If you want to test it, you can try to run this as a new .php file:
    PHP Code:
    <?php if( ?>
    When I run that, I get the following error:
    Parse error: syntax error, unexpected ';' in /home/.../test.php on line 1
    If you get that error, it means you have error reporting enabled. If not, there is a problem with error reporting.





    Edit: on an unrelated note, that's a weird error. I wonder why it claims there is a ';' when there isn't one in the code at all. Traq, any ideas?
    I suppose it really means "the end came too early", and it's just not phrased well.
    PHP has some weird error messages (but you learn to understand them with time). One of them (in the English version of PHP) is actually written in Indonesian-- some kind of weird typo!
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #20
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    when I run that as a new .php file I get the following error:

    Code:
    Parse error: syntax error, unexpected ';' in /home/userdir/foobar/errortest.php on line 1

Similar Threads

  1. Scroll in the DOWN direction.
    By runservers in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 03-11-2008, 09:29 PM
  2. I need to put in the URL a certain direction
    By k4but0x in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 02-21-2008, 10:14 AM
  3. Image Conveyer Belt Script - change direction
    By timgundry in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 08-13-2006, 09:51 PM
  4. new to databases. need direction.
    By wiklendt in forum MySQL and other databases
    Replies: 6
    Last Post: 06-27-2006, 04:30 AM
  5. Opening direction of Overlapping Content script
    By daCyclist in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 09-07-2005, 03:55 PM

Bookmarks

Posting Permissions

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