Advanced Search

Page 4 of 4 FirstFirst ... 234
Results 31 to 32 of 32

Thread: Need some direction with this script

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

    Default

    So I am making progress slowly but surely (in a great part due to the advice received here, so thanks for that). I currently have some error checking working and the script is INSERT ing the data into my database. I need to make sure that duplicate data is not entered into the database as well and have been looking at these SQL syntax options to accomplish it (INSERT...IGNORE, INSERT...ON DUPLICATE KEY UPDATE, and REPLACE INTO) does it really matter which I use or is there a better way?

    Here is my current code

    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 '10101038'//$_POST['playerid'];    
        
    $guid '4e72f140c35df55909ce551273c44007'//$_POST['guid'];
        
        /*if(!isset($_POST['playername']) ||
            !isset($_POST['playerid']) ||
            !isset($_POST['guid']) || {
            die('We are sorry, but there appears to be a problem with the form you submitted.');       
        }*/
            
            
    if(mb_strlen($guid)<32){ 
                echo 
    'the guid checked is less than 32 characters';
                }
            if(
    mb_strlen($guid)>32){
          echo 
    'the guid checked is more than 32 characters';
            }
            if(
    mb_strlen($player_id)<8){
              echo 
    ' the player_id you entered is less than 8 characters';
            }
            if(
    mb_strlen($player_id)>8){
            echo 
    ' the player_id you entered is more than 8 characters';
                }
     if(
    mb_strlen($guid)==32 && mb_strlen($player_id)==8){    
     
        
    $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>');
                 
    $mysqli->close();
                 exit;
                }
            


        

        
    $q "INSERT INTO player_data (player_name, player_id, guid) 
        VALUES ('
    $player_name', '$player_id', '$guid')"

    //Should I duplicate check here?

           
    if($r $mysqli->query($q)) {

    //or here?            
                    
         
    echo 'Player: ' $player_name ' ' $player_id ' ' $guid ' has been added to the whitelist.';

    }
    else {
      
    printf("error: %s\n"mysqli_error($mysqli));
        
        }
       
      
    }
    $mysqli->close();

    ?>
    Thanks

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

    Default

    I used this

    PHP Code:
    $duplicateResult=$mysqli->query("SELECT `player_name`,`player_id`,`guid` FROM `player_data` WHERE `player_name`='$player_name' OR `player_id`='$player_id' OR `guid`='$guid'");
    if(
    $duplicateResult->num_rows>=1) {

            echo 
    'Some of the information already exists in the database';
            
    $mysqli->close();
            exit;
            
      } 
    but I am having trouble if the duplicate message is triggered

    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 '10101038'//$_POST['playerid'];    
        
    $guid '4e72f140c35df55909ce551273c44007'//$_POST['guid'];
        
        /*if(!isset($_POST['playername']) ||
            !isset($_POST['playerid']) ||
            !isset($_POST['guid']) || {
            die('We are sorry, but there appears to be a problem with the form you submitted.');       
        }*/
            
            
    if(mb_strlen($guid)<32){ 
                echo 
    'the guid checked is less than 32 characters';
                }
            if(
    mb_strlen($guid)>32){
          echo 
    'the guid checked is more than 32 characters';
            }
            if(
    mb_strlen($player_id)<8){
              echo 
    ' the player_id you entered is less than 8 characters';
            }
            if(
    mb_strlen($player_id)>8){
            echo 
    ' the player_id you entered is more than 8 characters';
                }
     if(
    mb_strlen($guid)==32 && mb_strlen($player_id)==8){    
     
        
    $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>');
                 
    $mysqli->close();
                 exit;
                }
            



    $duplicateResult=$mysqli->query("SELECT `player_name`,`player_id`,`guid` FROM `player_data` WHERE `player_name`='$player_name' AND `player_id`='$player_id' AND `guid`='$guid'");
    if(
    $duplicateResult->num_rows>=1) {

            echo 
    'Some of the information already exists in the database';
            
    $mysqli->close();
            exit;
            
      }
        

        
    $q "INSERT INTO player_data (player_name, player_id, guid) 
        VALUES ('
    $player_name', '$player_id', '$guid')"

           if(
    $r $mysqli->query($q)) {
                
         echo 
    'Player: ' $player_name ' ' $player_id ' ' $guid ' has been added to the whitelist.';

      }

    }  
      

    $mysqli->close();

    ?>
    Last edited by itivae; 03-15-2013 at 07:37 PM.

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
  •