Page 1 of 4 123 ... LastLast
Results 1 to 10 of 32

Thread: Need some direction with this script

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

    Default Need some direction with this script

    Hi i am writing a script to check a guid against a column in a database. Here is what I have so far but I keep getting a "Parse error: syntax error, unexpected T_STRING in /home/mydir/foobar/guid-checker.php on line 39"

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>guid check</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <?php
    require_once('connectvars.php');

        
    $player_name 'itivae'//$_POST['playername'];    
        
    $player_id '1010103'//$_POST['playerid'];    
        
    $guid '4e72f140c35df55909ce551273c44006'//$_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.');       
        }*/
       
    $mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_NAME);
    /* check connection */
    if ($mysqli->connect_errno) {
        
    printf("Connect failed: %s\n"$mysqli->connect_error);
        exit();
            }  
            
    $query "SELECT banned_guid, player_id, player_name FROM player_data WHERE banned_guid = $guid
        
        if (
    $result = $mysqli->query($query)) {

        if (mysql_num_rows(
    $result)>0) {
        printf ('Unapproved ' . 
    $guid . ' ' . 'matches a guid on the ban list.');
       }  
    }    

    else {

        
        
    $query ="INSERT INTO player_data (player_nameplayer_idguid)
     
    VALUES ('itivae''1010103''4e72f140c35df55909ce551273c44006')";
    echo 'This player ' . 
    $player_name. ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.');
    }

    $mysqli->close();

    ?>
    </body>
    </html>
    Any help is appreciated. I may not even be going about this in the right manner as I am still new with php.

    Thanks in advance.
    Last edited by traq; 03-13-2013 at 11:10 PM. Reason: added [PHP] tags

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,010
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    Here's some info on what that error means and how to fix it: http://www.ehow.com/info_8717984_php...ed-string.html

    You'll need an editor with line numbering to make finding the problem easier - PSPad http://www.pspad.com/ and Notepad++ http://notepad-plus-plus.org/ are both free ones that should help, so open the guid-checker.php file in one of those and check line 43.
    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

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

    Default

    Hi Beverleyh,

    Thanks for the information. I have removed a great deal of the code (in an attempt to get at least part of it working correctly so that I have something to work off of), I am still getting a T_STRING error but now it is past the last line of code. I cannot see any glaring syntax errors (but maybe I have become blind to them after several hours).

    Here is the code I am working with:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>guid check</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <?php
    require_once('connectvars.php');

        
    $player_name 'itivae'//$_POST['playername'];    
        
    $player_id '1010103'//$_POST['playerid'];    
        
    $guid '4e72f140c35df55909ce551273c44006'//$_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.');       
        }*/
       
    $mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_NAME);
    /* check connection */
    if ($mysqli->connect_errno) {
        
    printf("Connect failed: %s\n"$mysqli->connect_error);
        exit();
            }  
        
    $query "SELECT banned_guid, player_id, player_name FROM player_data WHERE banned_guid = $guid"
        
        if (
    $result $mysqli->query($query)) {

        if (
    mysql_num_rows($result)>0) {
        
    printf ('Unapproved ' $guid ' ' 'matches a guid on the ban list.');
       }  
        }     

    else {
    echo 
    'This worked';
    }


    $mysqli->close();


    ?>
    </body>
    </html>
    Last edited by traq; 03-13-2013 at 11:39 PM. Reason: added [PHP] tags

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

    Default

    Oh *&%(*%(.....There is a missing " on line 41. Thanks for the help. I am going to leave this thread open for a minute in case I have another problem.

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

    Default

    So I have played with this a little more. Its seems to run but it is not accomplishing all of its tasks. It skips the first if statment and always evaluates to true making the "else" statment always run even when its false. I was hoping somone might have an idea of what I am doing wrong. Here is the displayed text:
    "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/userdir/foobar/guid-checker.php on line 31
    This player itivae 1010103 4e72f140c35df55909ce551273c44006 has been added to the whitelist.

    Here is the current code

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>guid check</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <?php
    require_once('connectvars.php');

        
    $player_name 'itivae'//$_POST['playername'];    
        
    $player_id '1010103'//$_POST['playerid'];    
        
    $guid '4e72f140c35df55909ce551273c44006'//$_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.');       
        }*/
       
    $mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_NAME);
    /* check connection */
    if ($mysqli->connect_errno) {
        
    printf("Connect failed: %s\n"$mysqli->connect_error);
        exit();
            }  
        
    $query "SELECT banned_guid FROM player_bans WHERE banned_guid = $guid"

     
    $result $mysqli->query($query);

        if (
    mysql_num_rows($result)>0){

        
    printf ('Unapproved ' $guid ' ' 'matches a guid on the ban list.');
        
       } 
        

    else {



        
    $query ="INSERT INTO player_data (player_name, player_id, guid) VALUES ('itivae', '1010103', '4e72f140c35df55909ce551273c44006')";
    echo 
    'This player ' $player_name' ' $player_id ' ' $guid ' has been added to the whitelist.';
    }

    $mysqli->close();

    ?>
    </body>
    </html>
    This always runs the else text but does not INSERT anything into the player_data table.

    Thanks
    Last edited by djr33; 03-13-2013 at 11:45 PM.

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

    Default

    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.

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

    Default

    Pardon my ignorance but could you please be a little more specific?

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Compare the good code and the bad code, paying close attention to the red parts. Look for patterns. With some practice you'll see it very quickly.
    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

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

    Default

    Text editors desgined for coding (or simply to accommodate coding) highlight different parts of your code in different ways, to help distinguish them. It's much easier to have everything color-coded than to stare at a long line of black-and-white gibberish, looking for a missing double-quote. The syntax highlighting used by the forum's [PHP] tags, for example, makes string values red, variable names blue, function names green, comments yellow, etc.:
    PHP Code:
    <?php

    $thisIsAVariable 
    "this is a string";

    /* this is a comment */
    thisIsAFunction$thisIsAVariable );
    Now, if you'd forgotten the closing double-quote on your string, you'd get a fatal error (something like "unexpected $end," in this case). But you'd be able to find the problem almost instantly, because you'd notice that your string was much larger than you intended it to be:
    PHP Code:
    <?php

    $thisIsAVariable 
    "this is a string;

    /* this is a comment */
    thisIsAFunction( 
    $thisIsAVariable );
    cool, huh?

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

    Default

    Alright I have been staring at this for more than an hour.... I have tried to rearrange the code. I am really stumped. Here is my current code....Feel free to hint at the answers...

    PHP Code:
    <?php
    require_once('connectvars.php');

        
    $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.');       
        }*/
       
    $mysqli = new mysqli(DB_HOSTDB_USERDB_PASSWORDDB_NAME);
    /* check connection */
    if ($mysqli->connect_errno) {
        
    printf("Connect failed: %s \n"$mysqli->connect_error);
        exit();
            }  
        
    $query "SELECT * FROM player_bans WHERE banned_guid='$guid'"

     
    $result $mysqli->query($query);


        if (
    mysql_num_rows($result)<1){
        
    $query "INSERT INTO player_data (player_name, player_id, guid) VALUES ('itivae', '1010103', '4e72f140c35df55909ce551273c44007')";
     echo 
    'This player ' $player_name ' ' $player_id ' ' $guid ' has been added to the whitelist.';
        
       } 
        

    else {

       echo 
    'Unapproved ' $guid .  ' matches a guid on the ban list.';


    }
    $mysqli->close();

    ?>
    Am I any closer? Do I need to look at the db connection closer? It seems to not trigger the error message so I am assuming it is connected (you know what they say about assumptions though). These are two separate tables I don't think I need a new connection for each db update but like I said I am not overly proficient with php and MySQL. Also on the INSERT INTO line is there supposed to be any syntax between the definition of the columns and the values inserted into the columns? From what I have read that string seems acceptable. Thanks for taking the time.
    Last edited by itivae; 03-14-2013 at 01:43 AM.

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
  •