Jump to content

pixy

Members
  • Posts

    295
  • Joined

  • Last visited

    Never

Posts posted by pixy

  1. I thought you meant that it was updating the wrong thing. I guess I misunderstood your post.

    So all of your items have their own iid, and each has their own damage?
    Which part of your script does that part? It's all a bit jumbled-looking to me. XD
  2. Here's something really quick...
    (i'm assuming $_SESSION['player'] is the player's user ID
    [code]
    <?php
    // Connect to database
    session_start();
    if (!isset($_SESSION['player'])) {
      echo 'You must log in.';
      include("footer.php");
      die();
    }
    else {
      $player = $_SESSION['player'];
    }

    if (isset($_GET['equip'])) {
      $errors = array();
      if (!is_numeric($_GET['equip'])) {
        $errors[] = 'You have accessed this page incorrectly.';
      }
      else {
       $equip = trim($_GET['equip']);
      }
      if (empty($errors)) {
        // Make sure they have the item first, and that it's not eqipped
        $query = "SELECT status FROM inventory WHERE (iid='$eqip' AND uid='$player')";
        $result = mysql_query($query);
        if (mysql_num_rows($result) == 1) { // Found item
          $row = mysql_fetch_array($result, MYSQL_NUM);
          $status = $row[0];
          if ($status == 0) { // Not equipped
            $query = "UPDATE inventory SET status=1 WHERE (iid='$eqip' AND uid='$player) LIMIT 1";
            $result = mysql_query($query);
            if ($result) {
                echo 'That item has been sucessfully equipped.';
            }
            else {
                echo 'The item could not be equipped due to a mySQL error:<br>'.mysql_error();
            }
         }
         else {
           echo 'That item is already equipped.';
         }
       }
       else {
        echo 'That item does not belong to you.';
       }
    }
    else {
       echo 'You have accessed this page in error.';
    }
    ?>
    [/code]

    I'm not sure if all my { } line up since this little box makes it hard to tell, but thats the jist of it.

    Then, when you are showing the actual items the person is carying, put a link below to equip.php?equip=1234 or whatever the ID of the item is.
  3. [quote author=fert link=topic=100512.msg396759#msg396759 date=1152841071]
    use
    $connection=@mysql_connect("host","user","password");
    [/quote]
    But if you use the @ it suppresses errors, which is not something you want. You need to see the errors to be able to fix them.

    try this:
    $connection = mysql_connect("host", "user", "password") or die(mysql_error());

    That way it'll tell you WHY the connection failed.
  4. Wouldn't you want to do a while loop for the inventory?

    In any case, it looks to me like you are making things WAY harder than they have to be. I think instead of making this massive file with all the actions happening, you should consider breaking them up. Then, you can use the $_GET method more effectively for purchasing and equipping the player's items.

    So you're having no problems buying the items? Just equipping them? Can you have more than one item and leave some of them unequipped?

    Would you mind if I just wrote an equip.php page for you instead of editing what you have now? It's somewhat ridiculously complicated for what *should* be a simple process.
  5. ^ I'm already using sessions to store their username.

    [quote author=akitchin link=topic=100488.msg396635#msg396635 date=1152823294]
    well if you want to get everyone that has been online in the last 5 minutes, you can use entirely MySQL functions:

    [code]SELECT username FROM online_users WHERE time_online > DATE_SUB(NOW(), INTERVAL 5 MINUTE)[/code]

    this will grab the username of anyone whose status was updated in the last 5 minutes (by checking if their hypothetical time_online field is more recent [or greater] than 5 minutes ago).

    don't forget to change the query to suit however you're storing the users and their time.
    [/quote]
    Thanks, that's just what I was looking for!
  6. I honestly do not understand OOP for my life, so I need to find a way to show users who are logged in without it.

    How would I go about doing that? It's my own user log in script I made. It has a bunch of fields, but still the basic username, password, email, etc.

    Are there any tutorials out there for doing this? I googled and didn't find what I was looking for.
  7. If I want to use mysqli extensions, do I have to change ALL my functions to mysqli? I've got so many regular mysql stuff it would be a royal pain to go in and change all of them.

    For example, if I connect to the database using mysql_connect, can I use mysqli_query() later in the same script?
  8. Just put it at the top of whatever page you're using.

    Or, create functions.php and put it in there. Then, just include it in every page you want to use the redirecting function in.

    include("functions.php");

    That way, you don't even have to worry about it. Just use the function to redirect.
    redirect("page.php", 0);
  9. A url redirect?
    Well, I made myself a function so that I dont have to worry about headers already sending since my website uses sessions and you're supposed to use header("Location: link.php"); or something like that...

    function redirect($path, $timeout=2, $type=X_REDIRECT_HEADER) {

        // Make sure the session isn't split
        if (strpos(urldecode($path), "\n") !== false || strpos(urldecode($path), "\r") !== false)
        {
            error('Tried to redirect to potentially insecure url.');
        }

        // force session to be written before redirecting
        session_write_close();

        $type = (headers_sent() || $type == X_REDIRECT_JS ) ? X_REDIRECT_JS : X_REDIRECT_HEADER;
        if ($type == X_REDIRECT_JS) {
            ?>
            <script language="javascript" type="text/javascript">
            function redirect() {
                window.location.replace("<?php echo $path?>");
            }

            setTimeout("redirect();", <?php echo ($timeout*1000)?>);
            </script>

            <?
        } else {
            if ( $timeout == 0) {
                header("Location: $path");
            } else {
                header("Refresh: $timeout; URL=./$path");
            }
        }
        return true;
    }

    Then, when I want to redirect, I just use this:
    redirect("link.php", 0);
  10. http://www.daydreamgraphics.com/d/tutorial/list/45/2
    http://www.daydreamgraphics.com/d/tutorial/list/46/2
    http://www.daydreamgraphics.com/d/tutorial/list/47/2

    Step by step tutorials for making a simple forum.

    (or, you could always simply install XMB or phpBB or even SMF--they're all free and pretty easy to set up)
  11. ^ That's essentially when I was suggesting. You could make an array of allowed types:
    $allowed = array('image/gif', 'image/jpeg', 'image/png');
    if (in_array($_FILES['upload']['type'], $allowed) {
      // Continue to process
    }
    else {
      // Tell them its bad
    }

    And replace ['upload'] with whatever the name of the input you use is.
×
×
  • 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.