More help with php?

Results 1 to 5 of 5
  1. #1
    DRGunZ 2 Creator wesman2232 is offline
    MemberRank
    Jan 2007 Join Date
    Erie, PALocation
    4,872Posts

    More help with php?

    I feel like I'm bothering the only two people who really help out with PHP here (SuperWaffle and Secured), but asking questions is the best way to learn so.

    I'm creating a "Send Item to Rank" script. I'm assuming it would be easiest to use an INNER JOIN to take the UGradeID from the Account table to check it's rank, and then take the CID from Character where the AID is equal to an AID with that rank.

    This may be unfinished as I made it in a test file while I was working out the bugs.
    PHP Code:
    <?php
    include("secure/config.php");
    include(
    "secure/functions.php");
    include(
    "secure/anti_sql.php");
    include(
    "language/$language.php");
    ?>
              <form action="test.php" method="post">
          <table width="350" align="center" height="60" border="0" style="font-weight:bold; color:#FF3300;">
           <tr><td><?php echo $admingmp['64'].' :'?></td><td align="right"><input type="text" name="itemid" class="tbl_colbor" /></td></tr>
           <tr><td><?php echo $admingmp['36'].' :'?></td><td align="right"><select name="rank" class="tbl_colbor">
           <option value="255"><?php echo $staff['1']; ?></option>
           <option value="254"><?php echo $staff['4']; ?></option>
           <option value="0"><?php echo $staff['6']; ?></option>
           <option value="253"><?php echo $staff['7']; ?></option>
           </select></td></tr>
           <tr><td></td><td width="130" align="right"><input type="submit" name="changerank" value="<?php echo $admingmp['4']; ?>" /></td></tr>
          </table>
          </form>
    <?php
          
    if(isset($_POST['changerank'])){
         
    $rank $_POST['rank'];
         
    $itemid $_POST['itemid'];
         
    $sql mssql_query("SELECT a.AID, b.CID FROM Account a INNER JOIN Character b ON a.AID = b.AID WHERE a.UGradeID='$rank'");
           if(!
    $rank OR !$itemid){
            echo 
    $admingmp['174'];
          }elseif(
    strlen($itemid)>9){
           echo 
    $admingmp['67'];
          }elseif(
    mssql_num_rows($sql)<>0){
         
    $CID mssql_result($sql1'CID');
         echo 
    $CID;
             
    $sql2 mssql_query("INSERT INTO CharacterItem (CID, ItemID, RegDate, RentDate, cnt) VALUES('$CID','$itemid',GETDATE(),GETDATE(),'1')");
            echo 
    $admingmp['66'];
          }else{
           echo 
    $admingmp['6'];
          }
    }
    ?>
    Thanks, and thank you for your time.


  2. #2
    Pee Aitch Pee Dave is offline
    MemberRank
    Mar 2011 Join Date
    The NetherlandsLocation
    722Posts

    Re: More help with php?

    Just to be clear:
    1) You fill in the itemid and select the grade
    2) You then want to find all the characters which have this grade
    3) Send the item to the inventory of all the characters with the grade

    You want it like that?
    For that to work you'll have to loop through the results of the query.

    I edited your script in a quickie (untested):
    http://pastebin.com/raw.php?i=rZsSuCDK

    You can also just make it so that it will send items to the storage instead of the inventory.
    1) Change the query so it will only select the aid of the account table where the grade is $rank.
    2) Loop through the results and send the item to the accountitem table.
    Last edited by Dave; 16-12-12 at 12:00 PM.

  3. #3
    DRGunZ 2 Creator wesman2232 is offline
    MemberRank
    Jan 2007 Join Date
    Erie, PALocation
    4,872Posts

    Re: More help with php?

    Quote Originally Posted by SuperWaffle View Post
    Just to be clear:
    1) You fill in the itemid and select the grade
    2) You then want to find all the characters which have this grade
    3) Send the item to the inventory of all the characters with the grade

    You want it like that?
    For that to work you'll have to loop through the results of the query.

    I edited your script in a quickie (untested):
    http://pastebin.com/raw.php?i=rZsSuCDK

    You can also just make it so that it will send items to the storage instead of the inventory.
    1) Change the query so it will only select the aid of the account table where the grade is $rank.
    2) Loop through the results and send the item to the accountitem table.
    Yeah, I want it to where it selects the AID's of the accounts whose UGradeID is $rank.
    Then I wanted to take the AID's found in the Account table and use those to select the CID of the characters who have that AID.
    Then send those CID's an item to their inventory (we don't use the storage)

    Basically, sending an item to all character's whose rank is $rank (includes multiple characters of the same account, so each character will have one)

    I'm going to take your edited one and work with it. Thanks!
    EDIT: Your script works perfect. Thanks again.

    Also, is "if(isset($rank))" necessary? Since it's a selection, it will default to the first option unless one is set. In my occasion, it doesn't have one so it's automatically always set at the first option.
    Last edited by wesman2232; 16-12-12 at 12:34 PM.

  4. #4
    Pee Aitch Pee Dave is offline
    MemberRank
    Mar 2011 Join Date
    The NetherlandsLocation
    722Posts

    Re: More help with php?

    Quote Originally Posted by wesman2232 View Post
    Yeah, I want it to where it selects the AID's of the accounts whose UGradeID is $rank.
    Then I wanted to take the AID's found in the Account table and use those to select the CID of the characters who have that AID.
    Then send those CID's an item to their inventory (we don't use the storage)

    Basically, sending an item to all character's whose rank is $rank (includes multiple characters of the same account, so each character will have one)

    I'm going to take your edited one and work with it. Thanks!
    EDIT: Your script works perfect. Thanks again.

    Also, is "if(isset($rank))" necessary? Since it's a selection, it will default to the first option unless one is set. In my occasion, it doesn't have one so it's automatically always set at the first option.
    Well, I would just use the $_POST values instead of assigning it to another variable.
    In that case you'll need isset because else it could spit out an undefined variable error and that error will show the full path of your web server. (And you don't want people to know that.)

    Here an example of what I mean: http://pastebin.com/raw.php?i=kSA0N8bg

  5. #5
    DRGunZ 2 Creator wesman2232 is offline
    MemberRank
    Jan 2007 Join Date
    Erie, PALocation
    4,872Posts

    Re: More help with php?

    Quote Originally Posted by SuperWaffle View Post
    Well, I would just use the $_POST values instead of assigning it to another variable.
    In that case you'll need isset because else it could spit out an undefined variable error and that error will show the full path of your web server. (And you don't want people to know that.)

    Here an example of what I mean: http://pastebin.com/raw.php?i=kSA0N8bg
    Alright, I see what you mean there, thanks for the info and all the help again.



Advertisement